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

How come I'm unable to change a Players health?

I currently have a vest system and it should be setting the health when a player has a vest but for some reason, it just won't work at all it works perfectly fine without doing that but while doing it it won't work at all what is going on?

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")

		---PlayerHealth
		local MaxHealth = Humanoid.MaxHealth
		local Health = Humanoid.Health
		
		---Vests
		local Vests = {

			["TanVest"] = Character:FindFirstChild("TanVest");
			["BlackVest"] = Character:FindFirstChild("BlackVest");
		}

		---VestLocator
		local charChildren = Character:GetChildren()

		local tanVest = table.find(charChildren, Vests.TanVest)
		local blackVest = table.find(charChildren, Vests.BlackVest)

		if tanVest then --This without the math works fine but with the math wont, same fo the elseif
			Health = 150
			MaxHealth = 150
			print("Player has a TanVest")
		elseif blackVest then
			print("Player has a BlackVest")
			Health = 200
			MaxHealth = 200
		else
			print("Player has no vest")
		end
	end)
end)

6 comments

0

did you look in the output? no errors?

0

None

0

maybe it doesnt trigger it for some reason? ive had the exact same problem some times, but ive noticed it only happened with LocalScripts. are you using a LocalScript? if so, you could probably benefit from using RemoteEvent:OnServerInvoke for that player.

0

I'm using a normal script

0

well, then, maybe you could use the reverse?: remoteEvent:OnClientEvent:connect() and in the ServerScript: remoteEvent:FireClient()

0

I actually tried that as a solution and it never did set the health and if I tried to do something like that for the if and elseif it wouldn't work like at all no text would be printed stating the vest a player has on

1 answer

✓ Accepted answer

you must humanoid.Maxhealth = 150 not maxhealth = humanoid.maxhealth , maxhealth = 150 this is a mistake of beginner scripter if you write maxhealth = 150 it just change the variable but you write humanoid.maxhealth it change value

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