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

Identify "Localplayer" in a serversided script?

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

✓ Accepted answer

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)

3 comments

0

I edited the first post and you can see what i wanted todo.

0

This updated version will check every time the leaderstat changes if that’s what you want.

0

Thanks that exactly what i wanted :P

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