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

Identify "Localplayer" in a serversided script?

Asked by
NewGPU 36
6 years ago
Edited 6 years ago

Alright so. I'm unable to figure out how to make this

game.Workspace.Localplayer.Humanoid.Health = 10

but with a serversided script and changing the Localplayer variable to something that works serversided.

For example

if game.Players.Localplayer.leaderstats.Power.Value == 35 then
    game.Workspace.Localplayer.Humanoid.Health = 10
    -- Just for testing print(Localplayer.Name + " has 35 in power" + game.Workspace.playername.Humanoid.Health == 10)
end

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

If you wanted to do it for all players, you can use PlayerAdded in a server script:

game.Players.PlayerAdded:Connect(function(plr)
    plr:WaitForChild("leaderstats"):WaitForChild("Power").Changed:Connect(function(newVal)
        if newVal == 35 and plr.Character then
            plr.Character:WaitForChild("Humanoid").Health = 10
        end
    end)
end)
0
I edited the first post and you can see what i wanted todo. NewGPU 36 — 6y
0
This updated version will check every time the leaderstat changes if that’s what you want. mattscy 3725 — 6y
0
Thanks that exactly what i wanted :P NewGPU 36 — 6y
Ad

Answer this question