I have a script for a text button that I want to prompt a purchase for the gamepass and if the player owns the gamepass I want to open a frame here is my code:
local players = game:GetService("Players") local MPS = game:GetService("MarketplaceService") local passId = 39692796 game.StarterGui.VipScreen.VipOpener.MouseButton1Click:Connect(function() game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) if MPS:UserOwnsGamePassAsync(player.UserId,39692796) then local UI = script.VIP:clone() UI.Parent = game.PlayerGui end end) end) end)
The script is in ServerScriptService, Thanks.
i see 3 problems
problem 1 is that you don't check each player individually, if one has the pass then every player can access the UI.
problem 2 is that you wait for a player to get added after you click the button.
problem 3 is that you clone the ui to the playergui, not the players individual screengui.
You could restructure the code as so:
local players = game:GetService("Players") local MPS = game:GetService("MarketplaceService") local passId = 39692796 game.Players.PlayerAdded:Connect(function(player) -- player joins player.CharacterAdded:Connect(function() -- avatar loads if MPS:UserOwnsGamePassAsync(player.UserId,39692796) then -- check for pass local fun, fun2 = nil, nil -- set some variables for functions fun = game.StarterGui.VipScreen.VipOpener.MouseButton1Click:Connect(function() -- button clicked local UI = script.VIP:clone() UI.Parent = player.PlayerGui -- add a screenui object, and then put the ui into there end) fun2 = game.Players.PlayerRemoving:Connect(function() -- player is leaving fun:Disconnet() -- cancel fun2:Disconnect() -- cancel end) end end) end)
there may be some errors in the code i edited but it should work
i hope this works