I am trying to make it so if you own a gamepass it gives you a gui you can open and close. but the problem is that When it detects the player owns the gamepass it gives it to him but if the player resets the gui disappears. Here is my code:
local UI = game.ServerStorage.Guis.RadarGui:Clone() --clone ui
local gamepassID = 17814605
local ms = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player) --player added event
if ms:UserOwnsGamePassAsync(player.UserId, gamepassID) then
print("Owns radar")
UI.Parent = player.PlayerGui
UI.Enabled = true
end
end)
this is a Script in ServerScriptService. Another problem is that I want it to appear and disappear when the player that owns it clicks L.
Turn off the ResetOnSpawn property for ‘RadarGui’, assuming it’s a ScreenGui
Also, you’re cloning the UI only once. If anyone else happens to join with the gamepass, the script will error. You should clone it for every time that a Player joins the game, as such:
local gamepassID = 17814605
local ms = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player) --player added event
if ms:UserOwnsGamePassAsync(player.UserId, gamepassID) then
local UI = game.ServerStorage.Guis.RadarGui:Clone() --clone ui
print("Owns radar")
UI.Parent = player.PlayerGui
UI.Enabled = true
end
end)
You should post another topic for this as it is currently straying off-topic. You’ll have to put a LocalScript inside of the GUI and make use of UserInputService.