Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with my gamepass script? [SOLVED]

Asked by
Bman8765 270 Moderation Voter
9 years ago

I'm honestly clueless on what to do. Basically I have a gamepass and when the user purchases it they have something they can do. In the end, I want the script to run and when they join the game if the player has the gamepass I want it to turn a textbutton visibility to true (Does not matter what the name of the gui is). I checked the wiki but there example just seemed to confusing for me. Maybe if someone could explain it a little more and show me how to do it I might get a better understanding. Thanks!

local GamePassService = game:GetService("GamePassService")
local GamePassId = 185260715

game.Players.PlayerAdded:connect(function(player)
    if GamePassService:PlayerHasPass(player, GamePassId) then
        print("Username: " ..player " got dat pass")
        game.Players[player].PlayerGui.MenuGUI.Menu.twoDoff.Visible = true
    end
end)

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Your error is line 7.

game.Players[player].PlayerGui.MenuGUI.Menu.twoDoff.Visible = true

The player parameter is equal to the player object that joins the game. It is not a string. You could technically do,

game.Players[player.Name]

but this is completely unnecessary and pointless! player is the player object, so you can use it directly!

player.PlayerGui.MenuGUI.Menu.twoDoff.Visible = true

In some situations, like when the player is lagging, you may want to delay the PlayerAdded event until their character is loaded, to prevent errors.

repeat wait() until player.Character

or, when using PlayerGui, delay the script until the PlayerGui is loaded.

player:WaitForChild("PlayerGui")
0
This is a script, should it be a localscript? Bman8765 270 — 9y
0
Whoops I see now, thanks lol my mistake. Bman8765 270 — 9y
0
It should be a server Script in Workspace or ServerScriptService. PlayerAdded events don't work well in LocalScripts, but we could edit the code to work correctly in LocalScripts if needed. Perci1 4988 — 9y
0
So what example would you use? The last one you wrote Perci? And also what line would you insert it into? raystriker6707 30 — 9y
0
WaitForChild() delays the script until the child exists, then returns that child. You can therefore use it directly, e.g. 'player:WaitForChild("PlayerGui").Gui:Destroy()' . I use WaitForChild() a lot when scripting for it helps prevent errors due to lag. Perci1 4988 — 9y
Ad

Answer this question