#While, For Loops (Nested)
1 messages · Page 1 of 1 (latest)
local tool = script.Parent
local i = 0
local Counter = 10
while true do
wait(1)
i = math.random(1,10)
if i == 5 then
for Counter = 10, 0, -1 do
wait(1)
print(Counter)
Counter = Counter - 1
if Counter == 0 and tool.Equipped == false then
print("Countdown Finished and he isnt holding the item")
break
end
if Counter == 0 and tool.Equipped == true then
print("Countdown Finished and he is holding the item")
break
end
end
Counter = 10
end
end
im trying to make a loop that randomly while you play it counts down from 10 to 0. if it reaches 0 and hes not holding the item its going to print as followed. if he is holding it then its also gonna print as followed on the script. i just learnt more about the for and while loops so there maybe errors
maybe not used efficiently either. but its what worked with the countdown for me
i do have a feeling about the equipped = true and false. as its not a boolean value. but im also requesting help for efficient ways to make this script much better.
and with adding 2 counters i know thats another problem but please any help
tool.Equipped sadly doesn't return ture or false, since its a RBXSignal, an event.
What i would do is, creating a coustom varaible, like local equipped = false
and then using tool.Equipped event set it to true, also for Unequipped, set it to false.
And now for the loop i would do somethings like this, less nested.
for i = 10, 0, -1 do
wait(1)
print(i)
end
if equipped then
print("Equipped")
else
print("Not equipped")
end
If you don't care about countdown print, i would just use task.delay(10, functionToCheckIfPlayerEquippedOrNot)