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

Why won't my GUI script work?

I created a script (located in serverscriptstorage) and it is supposed to make an ImageButton and Frame visible if they own a certain gamepass. I don't know what's wrong with it; Can anyone help?

local gamepass = 382406860

while true do
    if game:GetService("GamePassService"):PlayerHasPass(player, gamepass) then 
        script.Parent.Parent.StarterGui.ClassGui.Main.Vip.Visible = true
		script.Parent.Parent.StarterGui.ClassGui.Frame.Frame1.Visible = true
    end
end

1 answer

✓ Accepted answer

You would need a wait in a loop.


local gamepass = 382406860

while wait() do
    if game:GetService("GamePassService"):PlayerHasPass(player, gamepass) then 
        script.Parent.Parent.StarterGui.ClassGui.Main.Vip.Visible = true
        script.Parent.Parent.StarterGui.ClassGui.Frame.Frame1.Visible = true
    end
end

Edited Syntax/Error Accumulated

Although a wait is needed, The player must be defined,and Lines 6-7 are wrong, StarterGui is the main container for Gui elements, but PlayerGui is the current interface container of the elements found in StarterGui.

So, Without further ado.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(ch)
		if game:GetService("GamePassService"):PlayerHasPass(player,382406860) then
			local playerGui = player:WaitForChild("PlayerGui").ClassGui
			playerGui.Main.Vip.Visible = true
			playerGui.Frame.Frame1.Visible = true
		end
	end)
end)

4 comments

0

Wow! Thanks a lot!

0

Wait I just realized that the loop making everything visible as long as they have the pass was taken out. How could I put a loop back in? (I want them to still have the stuff visible after a respawn)

0

Oh! I believe CharacterAdded would help instead, because a loop will lag your game.

0

Thanks again!

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