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

why doesnt the gui go away if you dont have the gamepass?

local id = 1324880817
local Player = game.Players.LocalPlayer
game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
	
if game:GetService('GamePassService'):PlayerHasPass(plr,id)then
	Player.StarterGui.RadioGui.Button.Visible = true
else
	Player.StarterGui.RadioGui.Button.Visible = false
end
end)
end)

Error attempt to index upvalue 'Player' (a nil value)

1 answer

✓ Accepted answer

Okay so, for one, you don't need the second line. For two, a player doesn't have a StarterGui in them, they have a PlayerGui

For the differences between PlayerGui's and StarterGui's, click here

The script I'm going to give is for a Server Script. Everything new that will be added will be explained.

local id = 1324880817
local Players = game:GetService("Players") -- Gets the player service

Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		local RadioGui = plr.PlayerGui:WaitForChild("RadioGui") --Waits for the gui so there are no errors
		if RadioGui then --Makes sure that the gui is actually there
			local Button = RadioGui:WaitForChild("Button") --Waits for the button
			if Button then --Checks if the button is actually there
				if game:GetService('GamePassService'):PlayerHasPass(plr,id) then
				    Button.Visible = true
				else
				    Button.Visible = false
				end
			end
		end
	end)
end)

Hope that this helped, make sure to mark this as resolved if it did!

2 comments

0

thank you

0

Your welcome.

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