Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with waitforchild on npc? [closed]

Asked by 3 years ago
Edited 3 years ago

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) 
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. User#32819 0 — 3y
0
-Edited also this is a reward script Agent0fChaos0 14 — 3y

Closed as Not Constructive by User#32819, CreationNation1, Dovydas1118, and WideSteal321

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

0
You are the best Agent0fChaos0 14 — 3y
Ad