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

Can someone help me with my gamepass extra health script?

Asked by 5 years ago

I have a button that changes another button to be active if the player wants to turn the gamepass off in game, in the setting I made. How do I make it loop to constantly check if its Active so when they turn it on, it works right away. How can I use this script to do that, do I just put a loop in it?

local id = 5348469

game.Players.PlayerAdded:Connect(function(player)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
    if script.Parent.Active == true then
    local player = game.Players.LocalPlayer 
local char = player.Character 
char.Humanoid.MaxHealth = 500 
char.Humanoid.Health = 500 
end
    else
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

Hello! Most objects have an event .Changed, which allows you to detect when a change occurs on the object on ANY of its properties. so we are using this, because Active should be changed when it turns true, no matter what, and because i think Active is a bool value, you would do script.Parent.Active.Value to detect if it were true.

Heres the new edited script:

local id = 5348469

game.Players.PlayerAdded:Connect(function(player)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
        if script.Parent.Active.Value == true then
            local player = game.Players.LocalPlayer
            local char = player.Character
            char.Humanoid.MaxHealth = 500
            char.Humanoid.Health = 500
        else
            local player = game.Players.LocalPlayer
            local char = player.Character
            char.Humanoid.MaxHealth = 100
            char.Humanoid.Health = 100
        end

        script.Parent.Active.Changed:connect(function()
            if script.Parent.Active == true then
                local player = game.Players.LocalPlayer
                local char = player.Character
                char.Humanoid.MaxHealth = 500
                char.Humanoid.Health = 500
            else
                local player = game.Players.LocalPlayer
                local char = player.Character
                char.Humanoid.MaxHealth = 100
                char.Humanoid.Health = 100
            end
        end)
    else
        print("Player doesnt own: ".. id)
    end
end)
0
It didn't change the health. protectiverobos -50 — 5y
0
But there are no errors. protectiverobos -50 — 5y
0
Hmm, is it in a normal script? Cant be placed in a local script. popgoesme700 113 — 5y
0
Can you just give me a link to download the place file so i can see what your issue is? this should've worked popgoesme700 113 — 5y
Ad

Answer this question