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

How do I cause the script to keep repeating once one sequence is done?


wait(10)
dft = {} 
local plrs = #game:GetService('Players'):GetChildren()
Debounce = true
local seek = game.Lighting.AzureSword:Clone()
while true do
function GetPlayers()
    local c = game.Players:GetChildren() 
    for i = 1, #c do 
        table.insert(dft, c[i].Name) 
    end 
end

if plrs >= 1 then
function Randomize()
    GetPlayers()
    local d = math.random(1, #dft) 
    local s = d 
    local m = Instance.new("Message", game.Workspace) 
    m.Text = "The seeker is ... "..dft[s].."!" 
    wait(1) 
    m:Remove()
    local rndm = game.Players:FindFirstChild(dft[s])
  
if Debounce then
  for index, plr in pairs(game.Players:GetPlayers()) do
          local char = plr.Character or plr.CharacterAdded:wait() -- Get the character of the player

            local HRP = char:WaitForChild('HumanoidRootPart') -- Wait For the HumanoidRootPart
            HRP.CFrame = CFrame.new(170,1,131) -- CHange the XYZ with the position or use script.Parent.CFrame for example
        
    
end


  if (rndm ~= nil) then 
        local Player = rndm.Character
        Player:MoveTo(Vector3.new(238, 0.05, -1427))

			



    
if (rndm ~= nil) then 
	wait(20) 
	  local Player = rndm.Character
        Player:MoveTo(Vector3.new(170,1,131))
seek.Parent = rndm.Backpack
			seek.Character.HumanoidRootPart.CFrame = rndm
end

    
      

end
	
    
    end
end

while wait(10) do    
    print("Done waiting.")
        print("Randomizing.")
        Randomize()
break
    end


else
    local h = Instance.new("Message")
h.Parent = workspace 
h.Text = "Not enough players."
wait(10)
h:Remove()
end
	


    plrs = #game:GetService('Players'):GetChildren()
wait(10)
p = game.Players:GetChildren()
for i = 1,#p do
p[i].Character.Head:remove()
end


	

 local h = Instance.new("Message")
h.Parent = workspace 
h.Text = "Restarting game"
wait(10)
h:Remove()






This is my current code for a hide and seek based game. How would I make it so that once the round is over, the script restarts and is repeated again?

2 answers

Put the whole script inside a while loop*? .3.

What I would do is put that whole script as a function which will make it when you call the function out it will run the script until the function is over. When the round is over you can then make it where it runs the function.

wait(10)
dft = {} 
local plrs = #game:GetService('Players'):GetChildren()
Debounce = true
local seek = game.Lighting.AzureSword:Clone()
while true do
function GetPlayers()
    local c = game.Players:GetChildren() 
    for i = 1, #c do 
        table.insert(dft, c[i].Name) 
    end 
end

function Start()
if plrs >= 1 then
function Randomize()
    GetPlayers()
    local d = math.random(1, #dft) 
    local s = d 
    local m = Instance.new("Message", game.Workspace) 
    m.Text = "The seeker is ... "..dft[s].."!" 
    wait(1) 
    m:Remove()
    local rndm = game.Players:FindFirstChild(dft[s])

if Debounce then
  for index, plr in pairs(game.Players:GetPlayers()) do
          local char = plr.Character or plr.CharacterAdded:wait() -- Get the character of the player

            local HRP = char:WaitForChild('HumanoidRootPart') -- Wait For the HumanoidRootPart
            HRP.CFrame = CFrame.new(170,1,131) -- CHange the XYZ with the position or use script.Parent.CFrame for example


end
end

  if (rndm ~= nil) then 
        local Player = rndm.Character
        Player:MoveTo(Vector3.new(238, 0.05, -1427))






if (rndm ~= nil) then 
    wait(20) 
      local Player = rndm.Character
        Player:MoveTo(Vector3.new(170,1,131))
seek.Parent = rndm.Backpack
            seek.Character.HumanoidRootPart.CFrame = rndm
end




end


    end
end

while wait(10) do    
    print("Done waiting.")
        print("Randomizing.")
        Randomize()
break
    end


else
    local h = Instance.new("Message")
h.Parent = workspace 
h.Text = "Not enough players."
wait(10)
h:Remove()
end



    plrs = #game:GetService('Players'):GetChildren()
wait(10)
p = game.Players:GetChildren()
for i = 1,#p do
p[i].Character.Head:remove()
end




 local h = Instance.new("Message")
h.Parent = workspace 
h.Text = "Restarting game"
wait(10)
Start()
h:Remove()

I dont expect this to work because I did this right on the browser (I dont have studio with me right now) but it should go around those lines. If you need help I can try to get access to studio and help out. Sorry If I wasn't a help

1 comment

0

Almost forgot you can use a while wait(Timing) do or while true do to check if the match is going on with a value or something.

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