I've been trying for days to get this kill for money script. I've basically tried almost everything i could think of like put the script into the zombie humanoid leave it out of the zombie.I really don't know what to do at this point so i came here to see if anybody can help me with it.
local Humanoid = script.Parent.Zombie function PwntX_X() local tag = Humanoid:findFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local Leaderstats = tag.Value:findFirstChild("leaderstats") if Leaderstats ~= nil then Leaderstats.Cash.Value = Leaderstats.Cash.Value + 7 --Change Money to the stat that is increased. wait(0.1) script:remove() end end end end Humanoid.Died:connect(PwntX_X)
(by the way i'm making a zombie game if you can't already tell)
First of all, you're using script:remove()
, which is deprecated
; that means that it shouldn't and in the future can't be used anymore. Instead, use script:Destroy()
You should also capitalize the first letters in Destroy
, FindFirstChild
, Connect
.
Instead of all the if's, you can just use :WaitForChild()
instead of FindFirstChild()
. This will cause the script to stop if it can't find it, and thus you do not need the if statements.
I've fixed your code for you, let me know how it runs:
local Humanoid = script.Parent.Zombie ; Humanoid.Died:Connect(function() local tagValue = Humanoid:WaitForChild("creator").Value; local leaderstats = tagValue:WaitForChild("leaderstats"); leaderstats.Cash.Value = leaderstats.Cash.Value + 7; wait(0.1); script:Destroy(); end);