Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Doesn't My Player's MaxHealth Change?

Asked by 2 years ago

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

01local players = game:GetService("Players")
02local plr = players.LocalPlayer
03local char = plr.Character
04local hum = char:WaitForChild("Humanoid")
05local jumppower = hum.JumpPower
06local WalkSpeed = hum.WalkSpeed
07local HealthChange = hum.Health
08 
09game.ReplicatedStorage.HealthEvent.OnClientEvent:Connect(function()
10    hum.Health = script.Parent.CharacterSelection.Background.HealthValue.Value
11end)
12 
13 
14while wait() do
15    hum.JumpPower = script.Parent.CharacterSelection.Background.JumpValue.Value
16    hum.WalkSpeed = script.Parent.CharacterSelection.Background.SpeedValue.Value
17    hum.MaxHealth = script.Parent.CharacterSelection.Background.HealthValue.Value
18end

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

0
You have the change the health too MattVSNNL 620 — 2y
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 T3_MasterGamer 2189 — 2y
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 Sabailuridze 126 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago

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

1script.Parent.Touched:Connect(function(hit)
2    if hit.Parent:FindFirstChild("Humanoid") then
3        hit.Parent.Humanoid:TakeDamage(5)
4    end
5end)
0
bro thats not even close to what im asking Traadess 67 — 2y
0
Did not understand what you are asking, can you clarify? policepolopo 4 — 2y
Ad
Log in to vote
0
Answered by
bdam3000 125
2 years ago

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

Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

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

Answer this question