I made a gamepass called FastTravel, With it comes a gui that allows you to teleport to locations within the map, I have the gui working perfectly fine, but when I try to make a script that makes it so only people with the pass can use it, it never works.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local id = 5068130
game.Players.PlayerAdded:connect(function(player)
if MarketplaceService:UserOwnsGamePassAsync(player.userId, id) then
player:findFirstChild("PlayerGui").FastTravel.Main.Script.Disabled = false
player:findFirstChild("PlayerGui").FastTravel.Main.Script2.Disabled = true
else
player:findFirstChild("PlayerGui").FastTravel.Main.Script.Disabled = true
player:findFirstChild("PlayerGui").FastTravel.Main.Script2.Disabled = true
end
end)
- FastTravel is the gui
- Main is the open/close button
- Script is the open script
- Script2 is the close script
The GUI is usable by ALL players with this script active or not. How can i make it so only people that have the gamepass can use the gui?
[EDIT] I have made this script that controls an event named FastTravel
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.Main.Script.Disabled = false
player:findFirstChild("PlayerGui").FastTravel.Main.Script2.Disabled = true
else
player:findFirstChild("PlayerGui").FastTravel.Main.Script.Disabled = true
player:findFirstChild("PlayerGui").FastTravel.Main.Script2.Disabled = true
end
end)
When this event is fired by the script I made and put in the server script service it still does not work. Here is the code for the script
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)

1 comment
The server cannot access PlayerGui's descendants if they were not placed by the server. And connect, findFirstChild and userId are deprecated, use Connect, FindFirstChild and UserId.