Ad
Log in to vote
0

Problem running while wait loop?, i have not played roblox for a year at this point lol

Asked by 13 days ago

I am working on a script that mimicks the sine pattern(from trig), but the loop doesnt work?

local brick = script.Parent
local Time = tick()
local Runservice = game:GetService("RunService")

local randomInt = 20

function makeRandom()

    local currenttime = tick()
    local yOffset = math.sin(currenttime * math.pi*2) * 20
    brick.Size = Vector3.new(10, yOffset, 10)
end

while wait(0.05) do do
    makeRandom()
end

0
you added 2 do's at line 14 :p 0hsa 119 — 13d

3 answers

Log in to vote
0
Answered by 13 days ago

You have written do twice. remove one of them.

or you can add an extra end at the bottom, but I'd recommend the first way I told you about.

Ad
Log in to vote
0
Answered by 13 days ago

You have add 2 "do". This is telling the script to "do" twice which means you need to either add a second "end" or (This method is highly recommended) Just remove one "do", Like this:

    local brick = script.Parent
    local Time = tick()
    local Runservice = game:GetService("RunService")

    local randomInt = 20

    function makeRandom()

        local currenttime = tick()
        local yOffset = math.sin(currenttime * math.pi*2) * 20
        brick.Size = Vector3.new(10, yOffset, 10)
    end

    while wait(0.05) do 
        makeRandom()
    end

0
bruh you just said what i said bobifart 1 — 13d
0
We answered at the same time, I answered and when I reloaded the page your answer was here. wolftamer894 48 — 12d
Log in to vote
0
Answered by
Speedmask 197
13 days ago

hey, others have already given correct answers but I also suggest you do not use the expression while wait(x) do. wait() only works because the number it returns is truthy, which means it isn't actually true but it equates to true if you tried to check it. it's pretty inconsistent and confusing to use in your code and it's similar to using while true do.

I see you already have RunService imported. in your loop, consider doing one of these two:
if you want to actually wait 0.05 seconds every loop, do this:

while true do
    -- sine generator
    wait(0.05)
end

or better yet, to run the loop every frame, do this:

while true do
    -- sine generator
    RunService.Heartbeat:Wait()
end

see this devforum post

0
good point bobifart 1 — 12d

Answer this question