Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to index nil with waitforchild on npc?

Attempt to index nil with waitforchild on npc here's my code

 local Player = game.Players.LocalPlayer
 local Leaderstat = Player:WaitForChild("leaderstats")
 local Humanoid = script.Parent.Humanoid
 function Dead() 
 	Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 100
 wait(0.1) 
 script:remove()
 end 
 Humanoid.Died:connect(Dead) 

2 comments

0

This is not a script asking site. Try making one yourself, and if it doesn't work, post it here and we'll fix it for you.

0

-Edited also this is a reward script

1 answer

✓ Accepted answer

You cant access LocalPlayer with a server script.

	local Humanoid = script.Parent.Humanoid
	function Dead()
            for _, player in pairs(game.Players:GetPlayers()) do --Gets all players
           local Leaderstat = player:WaitForChild("leaderstats")
	   Leaderstats.Cash.Value = Leaderstats.Cash.Value + 100
          end
	wait(0.1)
	script:Remove()
	end
	Humanoid.Died:connect(Dead)

Hope it helps

1 comment

0

You are the best

This discussion is preserved as it was. New answers, comments, and votes are closed.