Hi im trying to make a button which says “Equip” if player has the gamepass and this will require me to make the button “Purchase” invisible.
local UI = game.StarterGui.ItemShopButton.Frame.ScrollingFrame.RainbowTrail --clone ui
local gamepassID = 86294878
local MS = game:GetService("MarketPlaceService")
--now check if the player has the gamepass
game.Players.PlayerAdded:Connect(function(player) --player added event
if MS:UserOwnsGamePassAsync(player.UserId, gamepassID) then --check if player has gamepass
UI.Parent = player.PlayerGui --set clone parent to playergui
UI.Enabled = false--set gui enabled to true (optional)
end
end)
I am currently using this script n serverscriptservice but it doesnt work as the purchase button (RainbowTrail" is still visible.
local Player = game.Players.LocalPlayer
local UI = Player.PlayerGui.ItemShopButton.Frame.ScrollingFrame.RainbowTrail
local gamepassID = 86294878
local MS = game:GetService("MarketPlaceService")
game.Players.PlayerAdded:Connect(function(player)
if MS:UserOwnsGamePassAsync(player.UserId, gamepassID) then
UI.Parent = player.PlayerGui
UI.Enabled = false
end
end)
StarterGui is what you see in studio, because GUI is client based, each client has their own UI located in the Player, PlayerGui
You tried to get the UI from StarterGui that is not the player local ui.
Try to find the ui when the Player is Added.
And the Button needs to be inside a Screen Gui to the list will be: ScreenGui > ItemShopButton etc… or ScreenGui > Frame > ItemShopButton etc…
Like this.
local gamepassId = 86294878
local MS = game:GetService("MarketPlaceService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local playerGui = player.PlayerGui
local UI = playerGui:WaitForChild("<NameOfScreenGui>")
if not UI then return end
if MS:UserOwnsGamePassAsync(player.UserId, gamepassId) then
UI.Enabled = true
else
UI.Enabled = false
end
end)
Each player has their own invidual folder for Gui’s, called PlayerGui, located in the players instance.
StarterGui is just a service that will automatically clone everything that’s in it, to the playergui; the player who joined.
Changing something from the StarterGui through a script will only change this for anyone else who joins, but in order to change something; like a gui, directly from a player, etc, you will need to access the PlayerGui.