Hello! I tried writing this very simple health script that I put in StarterCharacterScripts in order to replace the main one; I needed the regeneration value to be higher in case a value in a GUI was activated, to do so I used the GetPlayerFromCharacter in order to avoid using RemoteEvents. Seems not working and the script won't even work if normally put there, with no modifications. Mind helping me, please?
-- Gradually regenerates the Humanoid's Health over time.
local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 1 -- Wait this long between each regeneration step.
--------------------------------------------------------------------------------
local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'
local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
--------------------------------------------------------------------------------
if Player.PlayerGui.IGMenu.Focus.Reg1.Unlocked.Value == true then
local REGEN_RATE = 1.25/100
end
while true do
while Humanoid.Health < Humanoid.MaxHealth do
local dt = wait(REGEN_STEP)
local dh = dt*REGEN_RATE*Humanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
Humanoid.HealthChanged:Wait()
end

1 comment
did you forget to add the :LoadCharacter() function?