Help to my Entity!

Hey guy’s the title say’s all…
-I’ve been trying to make a Drugs for a new system im making. so far, none of my code has worked except for setting the model and setting the health and the spark-effect when destroyed.
this is supposed to give you +100 health, decreasing slowly, a small speed boost, and some more jumping power.

Everything seems to work, but the gamemode spams me with:


 Error: [gamemodes\darkrp\entities\entities\drugs\init.lua:36] attempt to index global 'D' (a nil value) 

I’ve been looking on the code i don’t see any Error’s but there is one, so i hope you guy’s can figure this out for me, in advance thanks!

[lua]function Drugged( ply )
ply:SetJumpPower(300)
local IDSteam = string.gsub(ply:SteamID(), “:”, “”)
if not timer.IsTimer(IDSteam…“DruggedHealth”) and not timer.IsTimer(IDSteam) then
ply:SetHealth(ply:Health() + 100)
timer.Create(IDSteam…“DruggedHealth”, 60/(100 + 5), 100 + 5, function()
if ValidEntity(ply) then D:SetHealth(ply:Health() - 1) end
if ply:Health() <= 0 then ply:Kill() end
end)
timer.Create(IDSteam, 60, 1, undrugged, ply)
end

end[/lua]

if ValidEntity(ply) then ply:SetHealth(ply:Health() - 1) end

Not sure where that D came from in your code, but just glancing at it, looks like it should be ply instead.

Thanks for your answer i’m gonna check it out now.

Edit:

Weee, it worked thank you!

Why didn’t you read the error before you posted?

I did, but i couldn’t find the answer… Tried a diffrent ways to fix the problem…

  • So i thought i found a solution but i didn’t soo here i am! :slight_smile: