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

How can I trigger functions in a script without waiting for it to finish before firing another one?

Asked by 2 years ago

local function action(Pick, part, OldFrame, OldSize) if Pick == 1 then for i = 1, 4 do part.Parent:SetPrimaryPartCFrame(part.CFrame + part.CFrame.UpVector * 2) wait(0.1) part.Parent:SetPrimaryPartCFrame(part.CFrame - part.CFrame.UpVector * 2) wait(0.1) end for i = 1, 20 do part.Parent:SetPrimaryPartCFrame(part.CFrame - part.CFrame.UpVector * 5) wait(0.05) end wait(3) part.Parent:SetPrimaryPartCFrame(OldFrame) end end while wait(1) do local index = math.random(1, #script.Parent.Grounds:GetChildren()) for i, v in script.Parent.Grounds:GetChildren() do if i == index then action(math.random(1, 2), v.Block, v.Block.CFrame, v.Block.Size) print('done') end end end

This is supposed to make different tiles in a little grid go down. How can I make it so it doesn't have to stop until one if finished in order to start another

3 answers

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

Well, you added wait() in your while loop, which you have to, but you i think you can use another type of loop, for i loop, like this:

for i = 1, 10 do -- 10 is the amount of times we will repeat this code
    print("banana!")
end

You can try something like that, there is no wait() so it should fire the print() function 10 times instantly.

Tho, If you mean that after firing the function it waits before firing it again, that's because your "action" function has wait() inside of it, so it will still yield the script.

0
well yeah I found the solution actually. Idk if you even read the script but it's supposed to take time to do the action. What I wanted to do is to fire the same function multiple times HeroFigo 81 — 2y
0
Yes, I did, but that's how wait() works, it yields the script, if you could post your solution for other people to know how you did it, it'd be nice as i've seen a couple people with this problem. SharkRayMaster 265 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

You can try using while true do is a good way to repeat make sure you add wait(.2) Example

while true do
wait()
blank --put your code you want to repeat
----
---
wait(.2)

Is this what your wanting?? Hope this helps!!

Log in to vote
0
Answered by 2 years ago

Alr. So what I wanted from this script is to trigger a function and work like a remote event. Just to start it but not wait for it to finish. and you can do that by just placing the function in a spawn()

For example:

local function gg(function(plr)
    spawn(function(plr)
        for i = 1, 50 do
        plr.leaderstats.Cash.Value += 5
        wait(0.2)
        end
    )
end)

while wait(1)
    gg(Player Variable)
end

This is going to run the function every one second but function is 10 seconds long. So it can run it multiple times without waiting the 10 seconds.

Answer this question