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

How would I make this rotation loop for a placing system more efficient?

Asked by 5 years ago
Edited 5 years ago

Hi, so I have been making a placing system for a game, and got stuck at rotation. After trying for a bit, I got this. But it is extremely inefficient and is very long. Any idea on how to make it more efficient?

Edit: Specifically the floor's rotation loop

Edit2: "floorRot" is a number that gets added to the model's CFrame via CFrame.Angles() whilst placing

01mouse.KeyDown:Connect(function(k)
02    if k:lower() == "r" and script.Parent.Parent.Parent.IsPlacing.Value then
03        if type then
04            if type == "floor" then
05                isRotating = true
06                while isRotating do
07                    if floorRot == 0 then
08                        floorRot = 10
09                    elseif floorRot == 10 then
10                        floorRot = 20
11                    elseif floorRot == 20 then
12                        floorRot = 30
13                    elseif floorRot == 30 then
14                        floorRot = 40
15                    elseif floorRot == 40 then
View all 96 lines...

1 answer

Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
5 years ago

To make your code shorter replace your if elseif statement with this:

1floorRot = floorRot +10
2if floorRot >180 then
3    floorRot = -170
4end
5-------
6wallRot = wallRot + 90
7if wallRot > 180 then
8    wallRot = -90
9end

Now to make your code more efficient is another story. Unfortunately i do not know what floorRot is supposed to do, so I can't help you with that. However, for smooth and efficient rotation I suggest using TweenService, rather than making timed increments.

0
Oh, sorry! I edited my answer to show what it does. mybituploads 304 — 5y
0
Actually I don't think it can be more efficient anyways mybituploads 304 — 5y
Ad

Answer this question