I have this while loop but it doesn’t seem to be working. Nothing is printed in the output besides hello.
local player = game.Players.LocalPlayer
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui2")
print("hello")
while true do
if player.items:FindFirstChild("LongStick").Value == true then
script.Parent.Visible = false
print("owned")
else
gui:WaitForChild("Shop").Stats.Frame.LongStick.EQUIP.Visible = false
print("not owned")
end
wait()
end
1 Like
You need to have a wait under both conditions, or just one wait at the start or end of the loop. It’s likely that you are having a timeout when the first condition is true.
1 Like
Hey there, unless you hit that else statement, that loop will crash your game. Be careful of this and add another wait() to the end.
Hm, I added a wait but it doesn’t seem to fix the problem
The problem isn’t the end its that it does that infinite times a second basically which crashes a computer or times out the script
Sorry I meant to say wait
This text will be blurred
That ain’t true. Theres a wait at the end.
Didn’t realize he edited it, I have no idea whats wrong with it although I would reccomend reworking it
Maybe try changing it to
local player = game.Players.LocalPlayer
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui2")
print("hello")
while true do
if if player:WaitForChild("items"):FindFirstChild("LongStick") and player.items:FindFirstChild("LongStick").Value == true then
script.Parent.Visible = false
print("owned")
else
gui:WaitForChild("Shop").Stats.Frame.LongStick.EQUIP.Visible = false
print("not owned")
end
wait()
end
1 Like
Is there any other function above this loop that’s running before this loop?
Can you try printing stuff outside of the if statement and see what prints?
Yeah, i added a high at the end of the while loop and it doesn’t print
local player = game.Players.LocalPlayer
local gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui2")
print("hello")
while true do
if player:WaitForChild("items"):FindFirstChild("LongStick") and player.items:FindFirstChild("LongStick").Value == true then
script.Parent.Visible = true
print("owned")
else
gui:WaitForChild("Shop", 8).Stats.Frame.LongStick.EQUIP.Visible = false
print("not owned")
end
print("hi")
wait()
end
Would anything print if you put it at the top of the loop?
I noticed you have WaitForChild() in your if statement. Does something like “Infinite yield possible on x” appear in the output?