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

(UNSOLVED) Help With GamePass Only Gui showing when clicking a button?

Asked by 2 years ago

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.

1 answer

Log in to vote
0
Answered by 2 years ago

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

0
Hm Wierd it's not adding to the players Gui and how would I make it so a purchase prompt pops up if you don't own the pass thanks. Puffyjasonrocks84 39 — 2y
0
replace line 10 to add it in to the player ui, as for the purchase prompt do it yourself watch a tutorial R_LabradorRetriever 198 — 2y
0
Ok Thanks Puffyjasonrocks84 39 — 2y
0
Yw R_LabradorRetriever 198 — 2y
Ad

Answer this question