I've created two scripts located in serverscriptservice. One of which fires a remoteevent when someone respawns or joins the game. The other is supposed to make that event enable a gui if the player owns a gamepass. The gui is enabled = false by default and is supposed to be switched to enabled as said before. Here are the code for the two scripts:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("FastTravel")
local gamePassID = 5068130
 
function onPlayerSpawned(player) 
 if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) then
	remote:FireServer()
else
	print("Does Not Have Pass")
 end
end 

game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function()
    onPlayerSpawned(player)
  end)
end)

Players.PlayerSpawned:Connect(onPlayerSpawned)

local repStorage = game:GetService("ReplicatedStorage")

local remote = repStorage:WaitForChild("FastTravel")

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

local id = 5068130

remote.OnServerEvent:Connect(function(player)
    if MarketplaceService:UserOwnsGamePassAsync(player.userId, id) then
player:findFirstChild("PlayerGui").FastTravel.Enabled = true 
else 
player:findFirstChild("PlayerGui").FastTravel.Enabled = false 
end
end)

For some reason even if the player has the gamepass the gui stays disabled. Help?

2 comments

0

I don't understand why you're having the server access PlayerGui. It should be the other way around. Have the server check if the player owns the game pass and then fire the client to enable the GUI.

0

So fire the client to enable the gui from a localscript instead of a regular script?