Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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
	

1 comment

0

you added 2 do's at line 14 :p

3 answers

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
 

2 comments

0

bruh you just said what i said

0

We answered at the same time, I answered and when I reloaded the page your answer was here.

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

1 comment

0

good point

This discussion is preserved as it was. New answers, comments, and votes are closed.