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

Attempting to change a vector to consistently go up and down? [Urgent, Need Answer soon]

Asked by 8 years ago
local x = 100.497
local z = -56.4

while wait() do
    for y = 26.892,23.892,-.1 do
        script.Parent.Position = Vector3.new(x,y,z)
    end
for yy = 23.892,26.892,.1 do
    script.Parent.Position = Vector3.new(x,yy,z)
end
end

That's the current script, its been awhile since I've done this so I'd like to know the following: -What do I need to change for the part to go up and then go down? Currently its not doing anything.

0
Please properly format your code so that people will be better able to help you. Programmix 285 — 8y
0
Sorrrryy, I forgot to format it and didn't check back. //qq konichiwah1337 233 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Here's the solution to your problem:

local x = 100.497
local z = -56.4

while wait() do
    for yup = 23.892,26.892,.1 do
        script.Parent.Position = Vector3.new(x,yup,z)
    end
    for ydown = 26.892,23.892,-.1 do
        script.Parent.Position = Vector3.new(x,ydown,z)
    end
end

All you really had to do is inverse the for loops. What the "yup" for loop does is change yup from 23.892 to 26.892 in increments of positive 0.1. "ydown" changes from 26.892 to 23.892 in increments of -0.1.

Here's a somewhat improved version of your script:

local basePosition = Vector3.new(100.497, 23.892, -56.4)

while wait() do
    for yup = basePosition.Y, basePosition.Y + 3, 0.1 do
        script.Parent.Position = Vector3.new(x, yup, z)
    end
    for ydown = basePosition.Y + 3, basePosition.Y, -0.1 do
        script.Parent.Position = Vector3.new(x, ydown, z)
    end
end

This solution just uses one Vector3 to represent a base position and manipulates it in a for loop to get the target position on the y-axis.

I would also recommend that you use a wait() somewhere in those for loops, otherwise it would be just like setting their position to the end-result of the for loop instantly.

Good luck! I hope this helps.

Ad

Answer this question