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

How Do I Make Scripts Start And Stop A Certain Times? [closed]

Asked by 5 years ago

For instance i have a game where you have to defend yourself from enemies in my case zombies and once you lose all your health you become knocked and its starts playing a crawling animation which i am also unsure how to do but then after a team comes to heal you its stop the animation and start standing again and running like normal.

0
Do you have an attempt to show us? Scripting Helpers is not a request site so if you are asking for a script, please stop. User#24403 69 — 5y
0
What complete moron voted against the close vote. Ridiculous. DinozCreates 1070 — 5y
0
Incapaz must be mad no one agreed with his other close request. DinozCreates 1070 — 5y
0
Can Anyone Help Odlnsonthor 11 — 5y

Closed as Not Constructive by TheeDeathCaster

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago

If you want the Script to repeat forever, then use while or repeat until, the first method can run however many times you like, can also have a circumstance required for the loop to run, repeat can also do this, yet both will immediately break whenever the given circumstance is no longer true. This would look like so

while true wait(BeforeNextRun) do --// it’s crucial you include a wait() as the loop can run too fast and cause the Studio to break
   local Part = Instance.new(“Part”); Part.Parent = workspace
   if (part ~= nil) then
      local CurrentCFrame = Part.CFrame
      Part.CFrame = Part.CFrame * Part.CFrame() + Vector3.new(CurrentCFrame.p)
   end
end

This will run forever, every time[BeforeNextRun]. If it’s a conditional statement, it would look like this

local Boolean = true
spawn(function()
while Boolean wait(BeforeNextRun) do
      local Part = Instance.new(“Part”); Part.Parent = workspace
      if (part ~= nil) then
         local CurrentCFrame = Part.CFrame
         Part.CFrame = Part.CFrame * Part.CFrame() + Vector3.new(CurrentCFrame.p)
      end
   end
end)

--// This will run until ‘Boolean’ is no longer true, you’ll also notice ‘spawn(function() end)’ that separates the loop and the rest of the Script, allowing the loop to run whilst not interrupting anything

wait(SameTimeAsBeforeNextRun * 3) --// After three loops then...

Boolean = false --// Notcie the loop stopped

You can also use break, this works for both methods. It can be called wherever inside the loop, yet be careful as break immediately breaks whichever loop it is called in. Sometimes if you have more than one and you call this method, whichever loop it was inside it will break the corresponding one, it will not break the first one.

Then you have repeat, it would look like this

local Boolean = true

spawn(function()
   repeat wait(BeforeNextRun) 

   local Part = Instance.new(“Part”); Part.Parent = workspace
   if (part ~= nil) then
      local CurrentCFrame = Part.CFrame
      Part.CFrame = Part.CFrame * Part.CFrame() + Vector3.new(CurrentCFrame.p)
   end

   until not Boolean --// Get’s opposite of ‘Boolean’, that would be false
end)

wait(SameTimeBeforeNextRun * 3)

Boolean = false

Unlike while, return always requires a conditional statement. Yet you can use return as a Yield, this would usually be seen at the top of a Script yet can be applied anywhere, this method is used to yield the Script until curtain requirements are met, would look like so

repeat wait() until --// circumstance

Hope this helps, spent a while putting this together, if so, don’t forget to Upvote and Accept this Answer! Good luck!

0
I dont understand tho how i would make it run when so and so happens and we its finished happening to then make it stop? Odlnsonthor 11 — 5y
0
Then don’t wrap the Script in a Loop, that’s if you want it to just run once, or write ‘break’ at the bottom Ziffixture 6913 — 5y
Ad