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

Please help me with this loop...Trying to make it restart if a certain value = ""?

Asked by 6 years ago

So I'm making a game, and I want it to check the value of a Value after a certain amount of time, and display Map Chosen: [Whatever Value] but if the value was equal to nothing, meaning no one voted, it would restart the cycle, but I have 0 clue on how to do this. This is what im attempting:

while true do
local val = game:GetService("ReplicatedStorage"):WaitForChild("MapChosen")
print("Voting For Map...")
wait(16)
if MapChosen.Value == "" then
    print("No one voting... re-voting")
    wait(3)
    print("Voting For Map...")
-- Here's where I have the issue. I don't know how to make it restart the loop from here. I want it to go back to line 4, but since there's no 'goto' commands, I have 0 clue how to.
end
else
print("Map Chosen: "..MapChosen.Value")
end

Any Help will be appreciated.

2 answers

Log in to vote
1
Answered by 6 years ago

Use repeat wait() until --parameterHere

while true do -- might want to change this
    local val = game:GetService("ReplicatedStorage"):WaitForChild("MapChosen")
    print("Voting For Map...")
    wait(16) -- if you still want to keep this given the below line
    repeat wait(3) until MapChosen.Value ~= "" -- pauses script until MapChosen exists
    print("Map Chosen: "..MapChosen.Value")
end
Ad
Log in to vote
1
Answered by 6 years ago

I might have an idea? im not very good at this so this may possibly not work


while true do local val = game:GetService("ReplicatedStorage"):WaitForChild("MapChosen") print("Voting For Map...") while true do wait(16) if MapChosen.Value == "" then print("No one voting... re-voting") wait(3) print("Voting For Map...") wait() else break print("Map Chosen: "..MapChosen.Value") end

(put it in a while true do loop, but if a map was picked it'll break the loop)

Answer this question