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

Help with changing health on transformation script?

Asked by 6 years ago
Edited 6 years ago

So I am making a transformation script. When you transform it invokes an event to change your max health to a certain number. When you leave it, it reverts to your normal max health. The thing is when you transform I have it set up to set your health to your new max health and when you un transform it sets your health to your original max health. This causes players to be able to heal themselves, how would I do this. The new max health does have a certain multi from the normal max health, that multi is 10. So would it work if when they transform I multi max health by 10 and normal health by 10? and then when I leave the transformation divide it by 10?

function game.ReplicatedStorage.On:OnServerInvoke(player)
    wait(2)
    player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth * 10
    player.Character.Humanoid.Health = player.Character.Humanoid.Health * 10
    end
end

function game.ReplicatedStorage.Off:OnServerInvoke(player)
    wait(2)
    player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth / 10
    player.Character.Humanoid.Health = player.Character.Humanoid.Health / 10
end

This has nothing to do with the firing the remote. Its just the script that it does that changes the characters health. I tested it and it works fine. But when they untransform the health they have goes way too low.

0
I have not yet tested this because last time it did not work for some odd reason XX_Scripta 11 — 6y
0
try using remote events Clasterboy 72 — 6y

1 answer

Log in to vote
0
Answered by
Despayr 505 Moderation Voter
6 years ago

Ofcourse it won't fire, you have given it no reason to.

On line 1, you used 2 periods Your functions are set up wrong. They need to connect to something.

local ReplicatedStorage = game:GetService("ReplicatedStorage") ---Use GetService()

local function Activate(player)
    wait(2)
    local Character = player.Character

    if Character then
        local Humanoid = Character:FindFirstChild("Humanoid")
        if Humanoid then
            Humanoid.MaxHealth = Humanoid.MaxHealth * 10
            Humanoid.Health = Humanoid.Health * 10
        end
    end
end


local function Deactivate(player)
    wait(2)
    local Character = player.Character

    if Character then
        local Humanoid = Character:FindFirstChild("Humanoid")
        if Humanoid then
            Humanoid.MaxHealth = Humanoid.MaxHealth / 10
            Humanoid.Health = Humanoid.Health / 10
        end
    end
end

ReplicatedStorage:FindFirstChild("On").OnServerInvoke:Connect(Activate)
ReplicatedStorage:FindFirstChild("Off").OnServerInvoke:Connect(Deactivate)
0
This has nothing to do with the firing the remote. Its just the script that it does that changes the characters health. I tested it and it works fine. But when they untransform the health they have goes way too low. XX_Scripta 11 — 6y
0
Is the MaxHealth based upon a stat? Despayr 505 — 5y
Ad

Answer this question