GUI buttons visible if gamepass = true

I want a single menu button on the screen, that when it is opened has many different different settings buttons. But I only want these settings buttons to be visible if the player hasPass = true. Currently I only have one button on the screen, along with a local script that checks if the pass is present when onPlayerAdded, then makes it visible accordingly. What I am trying to understand is how I could integrate this into a menu, so it is checked when the menu is opened? How or where would I set bool values, or would I?

You should provide the script you’re working with.

You should check on the server to prevent exploiters.

Currently just this (server script)

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = id  -- Change this to your game pass ID

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		local hasPass = false

		-- Check if the player already owns the game pass
		local success, message = pcall(function()
			hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
		end)

		-- If there's an error, issue a warning and exit the function
		if not success then
			warn("Error while checking if player has pass: " .. tostring(message))
			return
		end

		if hasPass == true then
			print(player.Name .. " owns the game pass with ID " .. gamePassID)
			player.PlayerGui.Walk.TextButtoncc.Visible = true
			-- Assign this player the ability or bonus related to the game pass
			character.Humanoid.WalkSpeed = 50
			print(character.Humanoid.WalkSpeed)
		end
	end)
end

-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)
if hasPass == true or MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) then
		print(player.Name .. " owns the game pass with ID " .. gamePassID
       	player.PlayerGui.Walk.TextButtoncc.Visible = true   -- Assign this player the ability or bonus related to the game pass
		character.Humanoid.WalkSpeed = 50
		print(character.Humanoid.WalkSpeed)
	end

This should do the trick for you

1 Like

Have a GUI button that when clicked, a LocalScript fires a RemoteEvent.

From there, you could check on the server if the player that clicked the GUI has the gamepass.