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

0 I don't know whar's wrong with this if not FindFirstChild loop?

Asked by 6 years ago
game.Players.PlayerAdded:connect(function(player)
 repeat wait() until player.PlayerGui:FindFirstChild("StartMenu")
 repeat wait() until player.Character:findFirstChild("Humanoid")

 player.PlayerGui.StartMenu.Frame.Visible = true
 player.Character.Humanoid.WalkSpeed = 0



while true do
wait(0.1)
if not player.Character:findFirstChild("StartMenu") then
 player.PlayerGui.ShopButton.Frame.Visible = true
 end
end

print('JoinedAndWorking!')
end)

player:WaitForChild('PlayerGui'):WaitForChild('ShopButton'):WaitForChild('Frame').Visible = true

worst localscript ive seen in a while.

0
This is a Bad Question (TM). The while loop will never exit, so it will never print "JoinedAndWorking" User#6546 35 — 6y
0
its FindFirstChild not findFirstChild and break your loop for god's sake Zafirua 1348 — 6y
0
i can feel you judging me RealRexTerm 21 — 6y
0
Dude please indent it makes code a lot easier to read. Zenith_Lord 93 — 6y

3 answers

Log in to vote
1
Answered by
Prestory 1395 Moderation Voter
6 years ago
Edited 6 years ago

Use WaitForChild like i did below its better to use.

game.Players.PlayerAdded:connect(function(player)
player.PlayerGui:WaitForChild("StartMenu")
player.Character:WaitForChild("Humanoid")

 player.PlayerGui.StartMenu.Frame.Visible = true
 player.Character.Humanoid.WalkSpeed = 0



while true do
wait(0.1)
if player.PlayerGui:FindFirstChild("StartMenu").Enabled then return 
    else player.PlayerGui.ShopButton.Frame.Visible = true
 end
end

print('JoinedAndWorking!')

player:WaitForChild('PlayerGui'):WaitForChild('ShopButton'):WaitForChild('Frame').Visible = true
end)




Ad
Log in to vote
0
Answered by
PolyyDev 214 Moderation Voter
6 years ago
Edited 6 years ago

In your while loop you have to use a break to ensure it carry's on down the code. A break basically exits the loop and lets the rest of the code run, instead of yielding at that while loop.

game.Players.PlayerAdded:connect(function(player)
 repeat wait() until player.PlayerGui:FindFirstChild("StartMenu")
 repeat wait() until player.Character:findFirstChild("Humanoid")

 player.PlayerGui.StartMenu.Frame.Visible = true
 player.Character.Humanoid.WalkSpeed = 0



while true do
    wait(0.1)
    if not player.Character:findFirstChild("StartMenu") then
        player.PlayerGui.ShopButton.Frame.Visible = true
        break
    end
end

    print('JoinedAndWorking!')
end)

player:WaitForChild('PlayerGui'):WaitForChild('ShopButton'):WaitForChild('Frame').Visible = true

Accept if it helped

Log in to vote
0
Answered by 6 years ago

You can use a break, but You might as well just use a repeat loop.

game.Players.PlayerAdded:connect(function(player)
 repeat wait() until player.PlayerGui:FindFirstChild("StartMenu")
 repeat wait() until player.Character:findFirstChild("Humanoid")

 player.PlayerGui.StartMenu.Frame.Visible = true
 player.Character.Humanoid.WalkSpeed = 0



repeat
wait()
until player.Character:findFirstChild("StartMenu")
 player.PlayerGui.ShopButton.Frame.Visible = true
 print('JoinedAndWorking!')
end)

player:WaitForChild('PlayerGui'):WaitForChild('ShopButton'):WaitForChild('Frame').Visible = true


Just a suggestion, because checking for a break seems pretty pointless

Answer this question