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

Help with loop?

Asked by
iLegitus 130
9 years ago

So im trying to fix this,But ive got no idea how.

while true do
    wait()                                                                              
    if Player.PlayerGui:FindFirstChild("ShopGUI") then
        Player.PlayerGui.ShopGUI.ValorUltra.MouseButton1Click:connect(clicked)
    else

    end
end

The idea is that the loop runs infinetly,So whenever "ShopGUI" is found in his backpack it runs the function once.

Anyone help?

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Why would you put a connection line in an if statement?

Instead of a while loop, try the ChildAdded event:

Player.PlayerGui.ChildAdded:connect(function (YourGUI)
    if YourGUI.Name == ShopGUI then
        --[[YourFunction]]()
    else
        return nil
    end
end)

Or

Player.PlayerGui.ChildAdded:connect(function (YourGUI)
    if YourGUI.Name ~= ShopGUI then 
        return
    end
    --[[YourFunction]]()
end)

If you want the function clicked() to fire, perhaps put the whole function clicked() function and the connection line to a different script, with its parent in the ShopGUI:

function clicked()
    --[[Your Statement]]
end

script.Parent.ValorUltra.MouseButton1Click:connect(clicked)
Ad

Answer this question