Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Game Pass Script Problems?

game.Players.PlayerAdded:connect(function(plyr)
	local gamePassService = game:GetService("GamePassService")
	if gamePassService:PlayerHasPass(plyr,258305700) then
		plyr.Character.PlayerGui -- eg (this line I want to access the StarterGUI)
	end
end)

Basically I want my script above to access the Player's StarterGUI, But how do I do it?

this script is in serverscriptservice.

Its prob an easy fix. Im still learning about the hierarchy of roblox. Thanks, ~bubs

2 answers

✓ Accepted answer

So anything that goes in the StarterGui goes into the player's PlayerGui. PlayerGui is a member of the plyr, plyr is a member of Players, and Players is a member of game. Visual: http://i.imgur.com/9qfxRtB.png

To fix your script:

game.Players.PlayerAdded:connect(function(plyr)
    local gamePassService = game:GetService("GamePassService")
    if gamePassService:PlayerHasPass(plyr,258305700) then
        playerGui = plyr.PlayerGui -- assigns a variable to the player's playergui. you could not assign it a variable if you want by simply saying, "plyr.PlayerGui"
    end
end)

game.Players.PlayerAdded:connect(function(plyr)
 local gamePassService = game:GetService("GamePassService")
if gamePassService:PlayerHasPass(plyr,258305700) then
plyr.Character.PlayerGui -- the PlayerGui isn't in the character, its in the player itself
end
end)

so the fix is

game.Players.PlayerAdded:connect(function(plyr)
 local gamePassService = game:GetService("GamePassService")
if gamePassService:PlayerHasPass(plyr,258305700) then
plyr.PlayerGui -- the PlayerGui isn't in the character, its in the player itself
end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.