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)
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)