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

Why won't my GUI script work?

Asked by 8 years ago

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

Log in to vote
1
Answered by
rexbit 707 Moderation Voter
8 years ago

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)
0
Wow! Thanks a lot! kelimeguy 60 — 8y
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) kelimeguy 60 — 8y
0
Oh! I believe CharacterAdded would help instead, because a loop will lag your game. rexbit 707 — 8y
0
Thanks again! kelimeguy 60 — 8y
Ad

Answer this question