Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me with my gamepass extra health script?

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

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)

4 comments

0

It didn't change the health.

0

But there are no errors.

0

Hmm, is it in a normal script? Cant be placed in a local script.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.