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

For some reason my 'Award points on death' system doesn't work, can someone help?

Asked by 3 years ago

I put this script inside a NPC with a humanoid inside it and this is a SS script

local plr = game.Players.LocalPlayer

if script.Parent.Humanoid.Health == 0 then
    plr.leaderstats.Currency.Value = plr.leaderstats.Currency.Value + 10
end
0
ServerScripts cannot run the local player JesseSong 3916 — 3y
0
Also, you should not use an if statement because it will run only once when the script is made. This will cause it to be false at the start and when a player kills the NPC, it wont run again. JustinWe12 723 — 3y

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago
Edited 3 years ago

Add a server script into serverscriptservice and use this code

game:GetService("Players").PlayerAdded:Connect(function(player)

    player.CharacterAdded:Connect(function(char)

        char:WaitForChild("Humanoid").Died:Connect(function()
            player.leaderstats.Currency.Value += 10
        end)

    end)

end)

So we are functioning when a player joins and check when the character joins so we can run a function to check when the player dies and when they do we are gonna reward the player some currency

0
you didnt even care to explain to a beginner. JesseSong 3916 — 3y
Ad

Answer this question