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

The face doesn't change when the health changed?

And i don't know how to determine the humanoid and character in server script.

Here the code:

Humanoid = game.Workspace:FindFirstChild(game.Players:GetChildren{Name}):FindFirstChild("Humanoid")
Character = Humanoid.Parent

if Character.Humanoid.Health >= 67 then
	Character.Head.face.Texture = "http://www.roblox.com/asset/?id=7506025"
	print("Work1")
end
		if Character.Humanoid.Health <= 66 then
			Character.Head.face.Texture = "http://www.roblox.com/asset/?id=7046277"
			print("Work2")
		end
			if Character.Humanoid.Health <= 24 then
				Character.Head.face.Texture = "http://www.roblox.com/asset	/?id=629906620"
				print("Work3")
			end
				if Character.Humanoid.Health == 0 then
					game.StarterPack.Stick.Handle.OuchEffect:Stop()
					Character.Humanoid.BreakJointsOnDeath = false
					Character.Head.face.Texture = "http://www.roblox.com/asset/?id=417334857"
					print("Work4")
				end

7 comments

0

you should use HealthChanged instead of a bunch of conditional statements

0

I used it and it doesn't work

0

how does it not work

0

I put the if statements inside health.changed and it doesn't work because i need to determind the humanoid first but i don't know how i determind humanoid in server side script

0

Humanoid.HealthChanged, not health.Changed

0

Thanks but it still doesn't work because it can't determind humanoid

0

alright I'll just post an answer

1 answer

To acquire the humanoid, you first need to find a Model that is associated with a Player. This is where PlayerAdded comes into play.

Usage of PlayerAdded:

game.Players.PlayerAdded:Connect(function(player) -- player is the player that has joined the game

Along with this comes CharacterAdded, which does what it sounds like it does:

player.CharacterAdded:Connect(function(char) -- char is the character of player

To find the Humanoid, since the Character has already loaded, you can just index it:

local hum = char.Humanoid

From here comes the RBXScriptSignal named HealthChanged.

HealthChanged fires when the value of Humanoid.Health has changed. When it fires it passes the new health value as the argument to the first parameter given.

Example usage of HealthChanged:

hum.HealthChanged:Connect(function(hp)
	if hp > 0 then
		print(hum.Name .. " is still alive with " .. hp .. " hitpoints remaining.")
	else
		print(hum.Name .. " has died.")
	end
end)

This should be more than enough to accomplish what you're going for.

2 comments

0

It's only work when you're dead for both condition

0

no it doesn't

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