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

How to change a Player's Health with a Local Script?

So, I am trying to make a Local Script that changes the Player's Health if their name are in the list, I have this Local Script but doesn't seems to be working.

local player = game.Players.LocalPlayer

local char = player.Character

if player.Name == "LokiGodOfThieves" then

char.Humanoid.MaxHealth = 500

else

char.Humanoid.MaxHealth = 100

end

1 answer

✓ Accepted answer

With FilteringEnabled, you'd have to check this on the server side. You could use a Remote Event if you like, but I would just connect a function that changes the max health to a CharacterAdded event.

-- server script
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	if player.Name == "LokiGodOfThieves" then
	-- if the player is LokiGodOfThieves
	-- make the player spawn with maxhealth of 500 every time their character spawns
		player.CharacterAdded:Connect(function(character)
			local humanoid = character:FindFirstChild("Humanoid")
			humanoid.MaxHealth = 500
		end)
	end
end)

Hope this helps! :)

3 comments

0

It's still not working for some reason.

0

That should be in a server script

0

Sorry I didn't pay attention, Thank you very much.

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