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

Make a script run through itself again after 30 seconds on an else statement?

Asked by 6 years ago

I want to make the script run again 30 seconds after the original else statement. Is there any way to make the script repeat only on an else statement? Thanks.

wait(10)
dft = {} 
local plrs = #game:GetService('Players'):GetChildren()
Debounce = true
local seek = game.Lighting.AzureSword:Clone()

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(10) 
      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(180)
if plrs >= 1 then
    p = game.Players:GetChildren()
for i = 1,#p do
p[i].Character.Head:remove()
 local h = Instance.new("Message")
h.Parent = workspace 
h.Text = "The hiders win."
wait(10)
h:Remove()

end
end

1 answer

Log in to vote
1
Answered by 6 years ago

You could encapsulate the code you need into a ModuleScript and require() it every time you need to repeat the code.

0
That wouldn't work unless you cloned the ModuleScript each time Amiaa16 3227 — 6y
Ad

Answer this question