I am trying to make my UI appear for everyone with at least one of my two certain gamepasses. It only shows for the first player to join with either of them. If another player joins, with the passes, it doesn’t pop up on their screen. I have tried for a few weeks now to try get it working.
The game creator enters a gamepass id for their donator perks. Any player with the gamepass, in their game, it will give them donator perks.
If the game creator has enabled DonateUI donator perks, people who donated to donateui, anyone with my gamepass, will get an altered version of the UI but with the same functionality.
If the player doesn’t have any of the passes, it won’t show.
The script listens to the PlayerAdded event and then checks with a service if the joined player Id owns the provided gamepass Id.
Here is the hierarchy.
It’s a good idea to place scripts under the ServerScriptService, it’s only accessible by the server. It’s in a secure spot.
The code to check for the game pass is as follows:
local MarketplaceService = game:GetService("MarketplaceService");
local Players = game:GetService("Players");
local DonatorGamePassId = 6365417; -- The gamepass Id to check for
Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, DonatorGamePassId) then -- If the joined player Id owns the DonatorGamePassId
script.DonatorUI:Clone().Parent = player.PlayerGui; -- Create a new DonatorUI and parent it to the PlayerGui
end
end)
Simply clone the UI into the joined PlayerGui if they do have the gamepass. The rest is for you to decide on what happens.
I have tried to use and alter the code for it to work, it doesn’t seem to work for me. It did when I tried it how you did, but not when I require a MainModule etc. If you would like to have a look at what I just tried, it’s here MainModule - DonateUI test - Roblox
local MarketplaceService = game:GetService("MarketplaceService");
local Players = game:GetService("Players");
local DonatorGamePassId = 6365417; -- The gamepass Id to check for
local DonateModule = require(script.MainModule);
Players.PlayerAdded:Connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, DonatorGamePassId) then -- If the joined player Id owns the DonatorGamePassId
DonateModule:Fire(player.PlayerGui, DonatorGamePassId, "Perk")
end
end)
I’m not sure what values need to go into the :Fire() method but you can figure that out. You may have to change the DonateModule path but make sure to put require() around it.