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

Why isn't this heal accelerating script working?

Asked by 10 years ago

This script's inside a model with two parts. Those two parts act as a healing area. When the player is inside or at least inside a specified radius(6 in this case) it should add 5 to their health every 2 seconds. Why is this not working? It isn't spitting anything out in Output.

Health=function()
    local H=script.Parent:GetChildren()
    local P=game.Players:GetChildren()
    for i=1,#H do
        while wait(2) do
            for i,Plr in ipairs(P) do
                local Char=Plr.Character
                if Char then
                    local T=Char:findFirstChild("Torso")
                    local Hum=Char:findFirstChild("Humanoid")
                    if T and Hum then
                        if Hum.Health>0 then
                            local PlrPosition=T.Position*Vector3.new(1,0,1)
                            local Heal=H[i].Position*Vector3.new(1,0,1)
                            if (PlrPosition-Heal).magnitude<6 then
                                Hum.Health=Hum.Health+5
                            end
                        end
                    end
                end
            end
        end
    end
end

Health()

Answer this question