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
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)
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!