I'm making a game that has a cash IntValue in it and it says that Players.CreeperAssassin005.Backpack.RustyShovel.Script:13: attempt to index local 'player' (a nil value). Any help?
script.Parent.blade.Touched:connect(function(hit) if script.Parent.CanDamage.Value == true then script.Parent.CanDamage.Value = false hit.Parent.Humanoid:TakeDamage(20) if hit.Parent.Humanoid.Health == 0 then local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local money = player.leaderstats.Cash money.Value = money.Value + 999999 end end end end)
try this
script.Parent.blade.Touched:connect(function(hit) if script.Parent.CanDamage.Value == true then script.Parent.CanDamage.Value = false hit.Parent.Humanoid:TakeDamage(20) if hit.Parent.Humanoid.Health == 0 then local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid ~= nil then if player ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local money = player.leaderstats.Cash money.Value = money.Value + 999999 end end end end end)
script.Parent.blade.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if script.Parent.CanDamage.Value == true then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local money = player:WaitForChild(“leaderstats”).Cash script.Parent.CanDamage.Value = false hit.Parent.Humanoid:TakeDamage(20) money.Value = money.Value + 999999 end end end)
script.Parent.blade.Touched:connect(function(hit) if script.Parent.CanDamage.Value == true then script.Parent.CanDamage.Value = false if hit.Parent:findFirstChild("Humanoid") then hit.Parent.Humanoid:TakeDamage(20) end if hit.Parent.Humanoid.Health == 0 then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local money = player.leaderstats.Cash money.Value = money.Value + 999999 end end end end)
And if that doesn't work, there is probably something wrong with your tool. Try debugging it before saying it doesn't work. Use print()
and warn()
.