So I already know how I can give abilities to players with stuff like swords, but now I want to know how
you can make a image button visible for only the player who owns the gamepass.
The issue is that when I try to make it it shows to all other players in the server.
Here’s the code;
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local gamePassID = ********
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
game.StarterGui.Menu.Menu2Frame.Selection.SelectionFrame.ImageButton.Visible = true
end
end
–Connect “PlayerAdded” events to the “onPlayerAdded()” function
Players.PlayerAdded:Connect(onPlayerAdded)
Image buttons might take a while to load, since downloading the image from the server might take a while. Use :WaitForChild when referencing it, does that work?
Judging from the output error, it’s because you don’t have the Menu gui on your PlayerGui. Make sure that it is the case by going on test mode and looking on your PlayerGui. It is also important to know the the names are caps sensitive.
Anything that is in StarterGui automaticly gets cloned to PlayerGui. If you change anything on the StarterGui, it changes for everyone else. Basically what I’m saying is, you don’t even have the Menu gui on StarterGui which is why there is no Menu gui on the PlayerGui.