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

How to make this looping script more smooth, and take up less space?

I believe this has something to do with math and I do not currently have the knowledge to understand that, in terms of lua, yet. That being said, how could I make this script work more smoothly?

while true do
	script.Parent.BorderSizePixel = 0
	wait(0.1)
	script.Parent.BorderSizePixel = 0.5
	wait(0.1)
	script.Parent.BorderSizePixel = 1
	wait(0.1)
	script.Parent.BorderSizePixel = 1.5
	wait(0.1)
	script.Parent.BorderSizePixel = 2
	wait(0.1)
	script.Parent.BorderSizePixel = 2.5
	wait(0.1)
	script.Parent.BorderSizePixel = 3
	wait(0.1)
	script.Parent.BorderSizePixel = 2.5
	wait(0.1)
	script.Parent.BorderSizePixel = 2
	wait(0.1)
	script.Parent.BorderSizePixel = 1.5
	wait(0.1)
	script.Parent.BorderSizePixel = 1
	wait(0.1)
	script.Parent.BorderSizePixel = 0.5
	wait(0.1)
	script.Parent.BorderSizePixel = 0
	wait(0.1)
end

3 comments

0

Edited your title to not sound so opinion based. Thank me later (you won't get your Q closed as opinion based)

0

Also BorderSizePixel can only be an integer.

0

Oh, thanks

2 answers

✓ Accepted answer

Use for loops.

https://www.lua.org/pil/4.3.4.html

Example:

for i = 3, 1, -1 do
	print(i)
end
print("test")

Output: 3 2 1 test

You can also add a wait(interval) in the loop (obviously) so there can be a delay, that is what we are going to do in this case.

So here is the code for what you are trying to achieve:

while true do
	for i = 1, 3 do 
		script.Parent.BorderSizePixel = i
		wait(0.1)
	end
	for i = 2, 1, -1 do
		script.Parent.BorderSizePixel = i
		wait(0.1)
	end
end

As incapaxx said, BorderSizePixel can't be an integer so the order goes like this: 1, 2, 3, 2 , 1. You can change that if you'd like of course.

1 comment

0

You meant to say BorderSizePixel can't be a float:)

Revised Script

while true do
	for a = 0, 3, 1 do
		script.Parent.BorderSizePixel = a
		wait(0.1)
	end
	for b = 3, 0, -1 do
		script.Parent.BorderSizePixel = b
		wait(0.1)
	end
end

Firstly, as incapaxx said, BorderSizePixel needs to be an integer, which is why the third argument is "1" and not "0.5"

Secondly, yes, you can shorten this code down using for-do loops, which will make the variable , in the first case "a" change by "1" from "0" to "3" every "0.1" seconds.

1 comment

0

thank you! just what i needed :)

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