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

Health script not working would like some help?

Asked by 9 years ago

I made my own custom regen script it works in studio but in a real server it does not work i checked f9 for errors but none. it does seam to work if i disabled it and enable it is there a way to fix this this but it only works if i disable and re enable it by clicking the check box. here is both scripts i used the first 1 switches them and the second 1 is the regen script i custom made.

--script 1
player =game.Players.LocalPlayer
wait()
char = player.Character
oldhealth = char:WaitForChild("Health")
newhp = script.Health
if oldhealth then
    oldhealth:remove()
    newhp.Parent = char
    newhp.Disabled = false
    script:remove()
end
-- script 2
--Responsible for regening a player's humanoid's health

-- declarations
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local Figure = script.Parent
local Head = Figure:WaitForChild("Head")
local Humanoid = Figure:WaitForChild("Humanoid")
local mr = player:WaitForChild("MaxRegen")
if mr then print("MaxRegen Found") end
local regening = false

-- regeneration



function regenHealth()
    if regening then return end
    regening = true

    while Humanoid.Health < Humanoid.MaxHealth do
        wait(0.3)
        local health = Humanoid.Health
        if health > 0 and health < Humanoid.MaxHealth and Humanoid.MaxHealth <=100 then
            health = health + mr.Value 
            Humanoid.Health = health
        end
    end

    if Humanoid.Health > Humanoid.MaxHealth then
        Humanoid.Health = Humanoid.MaxHealth
    end

    regening = false
end

Humanoid.HealthChanged:connect(regenHealth)

if any one can fix i would greatly appreciate it

0
Is this a local Script? BinaryResolved 215 — 9y
0
this first script is but the second 1 is a normal script the second 1 goes into the player char so i don't think it need to be local ill try it as a localscript User#9293 0 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Some nit-picky things here to start: Line 2 of your first script, there is no space between player = game.Players.LocalPlayerIt shouldn't really affect anything, but it is there.

--script 1
player =game.Players.LocalPlayer
wait()

The "wait" time is not specified... this could be a potential stopping point for your script.

Line 18:

    if regening then return end

Your if statement has an argument, but no condition... Maybe try:

function regenHealth()
    if regening == true
        then return -- I typically have it return something to to the output so I can determine if the script is running properly until that point.
    end

Let me know if this helps at all, I would be glad to look at it more if this does not work for it.

Ad

Answer this question