This script performs a points on kill reward. Somewhere after the (-3) test i get an 'attempt to index field 'Parent' (a nil value)' error and I have no idea how to fix it.
StatName = "Points" IncreaseValue = 20 print("-1")--test local Humanoid = script.Parent.Humanoid print("-2")--test function Killed() print("-3")--test local tag = Humanoid:findFirstChild("creator") if tag ~= nil then print("*4")--test if tag.Value ~= nil then print("1")--test local Leaderstats = tag.Value:findFirstChild("leaderstats") if Leaderstats ~= nil then Leaderstats[StatName].Value = Leaderstats[StatName].Value + IncreaseValue print("2")--test wait(0.1) print("3")--test end end end end Humanoid.Died:connect(Killed)
Humanoid is equal to nil, probably because it isn't created in time. Instead of using FindFirstChild to get the character's Humanoid, try using WaitForChild, which will keep trying to get it until Humanoid does not equal nil.