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
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.
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
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