Why is this script only happening once?

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.

Module: DonateUI Module - Roblox
Loader: DonateUI - Roblox

If you can help I will greatly appreciate it!

It would be better if you could show the code here if possible.

Theres alot of scripts and it’s written like a mess, I can do it, it’ll take a while.

Then its fine I’ll just get the model then.

1 Like

I apologise! Sorry. :slight_smile:

So if I understand correctly, you have 2 game passes. If a player joins and has none of them, prompt them with the passes UI?

If a player has one of them, prompt them with the other pass UI?

If a player has both, prompt them with nothing?

This is how my model works:

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.

So if I donate (by buying a game pass), I get a UI on my screen when I join the game?

This is how it’s meant to work yes.

Ok, easy enough, give me a few minutes.

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.

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

Since you want to use a module, try this instead:

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.

1 Like

Could you have a look for me if possible? It’s all messy on my end. MainModule - DonateUI test - Roblox