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

Why Doesn't My Player's MaxHealth Change?

I made a localscript where when a remote event is fired through the server, the health of the player changes to the value of an IntValue named "HealthValue" . I also made a while wait loop which constantly sets the max health of the player to the IntValue. There are also some other things in this script that aren't relevant to the problem

local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local jumppower = hum.JumpPower
local WalkSpeed = hum.WalkSpeed
local HealthChange = hum.Health

game.ReplicatedStorage.HealthEvent.OnClientEvent:Connect(function()
	hum.Health = script.Parent.CharacterSelection.Background.HealthValue.Value
end)


while wait() do
	hum.JumpPower = script.Parent.CharacterSelection.Background.JumpValue.Value
	hum.WalkSpeed = script.Parent.CharacterSelection.Background.SpeedValue.Value
	hum.MaxHealth = script.Parent.CharacterSelection.Background.HealthValue.Value
end

I tested this script using a kill brick that decreases the player's health by 5 each time, and the value of the health and the maxhealth do change, however, when i touch the killbrick, the health resets to 100 and 100 becomes the maxhealth as well. Any ideas how to fix? Thanks. Also keep in mind, that the player's humanoid's maxhealth does display the IntValues value, and this doesnt give any errors either

3 comments

0

You have the change the health too

0

What is your goal? It’s kind of hard to read (not grammarly). Like make it more understandable of what do you want to achieve

0

I think problem you are having is because you are changing MaxHealth and Health from LocalScript, try using Remote events, place server script in serverscriptservice

3 answers

If you are trying to make a brick that damages a player by 5 each time it is touched. The simplest method is,

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(5)
	end
end)

2 comments

0

bro thats not even close to what im asking

0

Did not understand what you are asking, can you clarify?

You can't set player health on the client (to prevent exploiters) except if you set it to 0 which will make the player die. You would have to set the player's health on the server.

Doing the loop on the server isn't the best way to go about either because it will degrade performance. You might want to use a different method instead of looping.

If you really want to use your current method, then you have to loop and set the player's health in a Server script

hey you! have you ever heard of enes? if you are in trouble, better call enes!

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