Hello, any help anyone can give would be greatly appreciated
I have got a couple of gamepasses that ‘unlock’ teleports when purchased, however the script didn’t make them visible (if invisible) and invisible if visible.
My script currently
local id = 9181149
game.Players.PlayerAdded:connect(function(player)
if game:GetService("GamePassService"):PlayerHasPass(player, id) then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
end)
The script is inside the button and they are set to invisible by default currently in a bid to try and resolve the issue, but i had no such luck. Like i said, any help would be greatly appreciated. Thanks!
Try using MarketplaceService instead of GamePassService.
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
GamePassService is used for legacy Roblox games. It is always a good idea to check the Roblox API reference since sometimes certain coding methods have newer replacements.
What kind of script is this? If it’s a LocalScript, there’s no reason to use the PlayerAdded event since you can just check the LocalPlayer. If it’s a server Script, you shouldn’t be manipulating UI at all with it.
Like I said, you shouldn’t be using the PlayerAdded event in a LocalScript. The player will have already joined by the time the localscript starts running. Just define player as the LocalPlayer, or game:GetService("Players").LocalPlayer.
Instead of having the whole .PlayerAdded:Connect... bit, just do local player = game:GetService("Players").LocalPlayer. The full script would look something like this:
local player = game:GetService("Players").LocalPlayer
script.Parent.Visible = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id)
Ok, i shall do that now! Ill let you know what happens. Also, does it matter if the button is enabled/disabled by default before the script changes it?