Getting humanoid from local script under a Text Button

Here I am trying to have it so when player presses text button, cooldown happens that all works however the part that is not working is making it so the players health goes to a higher value and the nametag above the head is changed.

Not sure why but I know its an issue with grabbing the player from the workspace

local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local hum = Char:WaitForChild('Humanoid')
yes = false
script.Parent.MouseButton1Click:Connect(function(plr)
	if script.Parent.Value.Value == 10 then
	
	script.Parent.Text = ("Safe in:"..script.Parent.Value.Value)
	yes = true
	while yes == true do 		
		script.Parent.Value.Value = script.Parent.Value.Value - 1
		script.Parent.Text = ("Safe in: "..script.Parent.Value.Value)
			if script.Parent.Value.Value <= 0 then
				yes = false			
			end
			wait (1)		
	end
		script.Parent.Text = "Safe"
		script.Parent.Value.Value = 45					
		Char.Head.NameTag.Injury.Text = "Safe Mode"		
		hum.Health = 9999	
	end
end)

The problem is, you are setting the humanoid’s Health property when you should be setting the humanoid’s MaxHealth property.

Try

hum.MaxHealth = yourNumberHere
hum.Health = yourNumberHere
1 Like

…could you specify exactly what isn’t working?

i see multiple problems:
as this is a localscript, meaning that the character nametag and health won’t change for everyone on the server, if they take damage on the server they’d die as usual.

defining variables without the ‘local’ keyword is deprecated

you’d also want to set the maxhealth property of the humanoid before changing its’ health to something far higher

for client-server communication:


local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local hum = Char:WaitForChild('Humanoid')
yes = false
script.Parent.MouseButton1Click:Connect(function(plr)
	if script.Parent.Value.Value == 10 then
	
	script.Parent.Text = ("Safe in:"..script.Parent.Value.Value)
	yes = true
	while yes == true do 		
		script.Parent.Value.Value = script.Parent.Value.Value - 1
		script.Parent.Text = ("Safe in: "..script.Parent.Value.Value)
			if script.Parent.Value.Value <= 0 then
				yes = false			
			end
			wait (1)		
	end
		script.Parent.Text = "Safe"
		script.Parent.Value.Value = 45					
		Char.Head.NameTag.Injury.Text = "Safe Mode"		
		hum.MaxHealth = 9999	
		wait(0.1)
		hum.Health = 9999		
	end
end)

Its like I understand I missed that part now its the nametag unsure what the issue is with that nothing prints in output

So for it to be serversided, for everyone Id need to do it what way server script with remote events?