Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make while true script only run once if while true do is required for it to work?

So, it seems the only way to make a script sense a Numbervalue is by constantly checking. However doing this seems to loop the script over and over, which is a problem since it deletes and copys.

no errors in output. I assume the reason it isnt working is because it creates multiple copies of 1 model so the script dosent know which one to delete.

TL:DR only way to detect number change is a loop to constantly check but I need it to only run the script once if the number is that value.

local AI = script.Parent.Parent.Timer.PositionNumber

local Lighting = game.ServerStorage

local World = game.Workspace

local Footstep = script.Parent.Parent.Timer.RemoteFunction.Footstep.Sound

while true do
    wait() 
    if AI.Value == 1 then
        script.Parent.Transparency = 1
Lighting.Walk1:Clone().Parent = game.Workspace
World.Neutral:Destroy()
Footstep:Play()
    end
end

2 answers

Maybe you could do something like this: (To clarify I have not tested it)

local AI = script.Parent.Parent.Timer.PositionNumber

local Lighting = game.ServerStorage

local World = game.Workspace

local Footstep = script.Parent.Parent.Timer.RemoteFunction.Footstep.Sound

while true do
    wait() 
    if AI.Value == 1 then
        script.Parent.Transparency = 1
Lighting.Walk1:Clone().Parent = game.Workspace
World.Neutral:Destroy()
Footstep:Play()
   else
	AI.Value = AI.Value + 1 -- added only this line and the else
    end
end

2 comments

0

im sorry, but that is not what im trying to do. adding 1 to the counter would make it the next phase, but I want randomization only.

0

oh ok

For the while loop, you could do "while AI.Value == 1 do" and then break the loop when your code has been executed, so it does not loop more than once when the value = 1.

while AI.Value == 1 do -- It will be constantly checking but the code won't run until the value = 1
	wait() 
        script.Parent.Transparency = 1
	Lighting.Walk1:Clone().Parent = game.Workspace
	World.Neutral:Destroy()
	Footstep:Play()
	break -- This will stop the loop and it will not loop anymore
end

Hope this helps!

1 comment

0

it does not. now the script wont detect the value at all.

This discussion is preserved as it was. New answers, comments, and votes are closed.