Not my luckiest day today, 2nd time on the Devforum asking for help…
Trying to get my Kill For Cash script working, Thought I did everything right, no errors, what is wrong…
basically the script makes it so that once you kill an npc, you get cash for it.
Please help fix it…
local Humanoid = script.Parent.Humanoid
function Dead()
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
local leaderstats = tag.Value:FindFirstChild("leaderstats")
if leaderstats ~= nil then
leaderstats.Points.Value = leaderstats.Points.Value +10
wait(0,1)
script:remove()
end
end
end
Humanoid.Died:Connect(Dead)
Are you setting tag.Value to the player object?
Try print debugging to see where the script stops.
function Dead() print("died")
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
print("found tag")
local leaderstats = tag.Value:FindFirstChild("leaderstats")
if leaderstats ~= nil then
print("found leaderstats")
leaderstats.Points.Value += 10
wait(0.1)
script:Destroy()
end
end
end
yep, here is my current script, all of my zombies are in a folder in the workspace, would that have anything to do with it?
local Humanoid = script.Parent.Humanoid
function Dead() print("died")
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
print("found tag")
local leaderstats = tag.Value:FindFirstChild("leaderstats")
if leaderstats ~= nil then
print("found leaderstats")
leaderstats.Points.Value += 10
wait(0.1)
script:Destroy()
end
end
end
Humanoid.Died:Connect(Dead)
local Humanoid = script.Parent.Humanoid
function Dead()
local creator = Humanoid:FindFirstChild("creator")
if creator ~= nil then
local ls= game.Players[tag.Value]:FindFirstChild("leaderstats")
if ls~= nil then
ls.Points.Value += 10
wait(0.1)
script:Destroy()
end
end
end
Humanoid.Died:Connect(Dead())
I changed the variable name from “tag” to “creator”. Whenever the zombie dies there should be a value called “creator” that has a value which is the player who killed the zombie. It must not be making the value. Which weapon system are you using?
function Dead() print("died")
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
print("found tag")
local leaderstats = tag.Value
if leaderstats ~= nil then
print("found leaderstats")
leaderstats.Points.Value += 10
wait(0.1)
script:Destroy()
end
end
end
Tell me if it’s working and click on Solution Button!
I am using guns that my friend coded, but it didnt work with a regular Roblox sword either. I am putting it under the zombie in the server script as well.