Up and Down Platform is moving weirdly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So it doesnt move foward
  2. What is the issue? Include screenshots / videos if possible!
    It moves up and down but also foward?
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I havent found any
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- Platform Script
local speed = 20

local start = script.Parent:WaitForChild("Start")
local finish = script.Parent:WaitForChild("Finish")


local attach0 = Instance.new("Attachment")
attach0.CFrame = CFrame.new()
attach0.Parent = script.Parent

local attach1 = Instance.new("Attachment")
attach1.CFrame = finish.CFrame
attach1.Parent = game.Workspace.Terrain

local pris = Instance.new("PrismaticConstraint")
pris.ActuatorType = Enum.ActuatorType.Motor
pris.MotorMaxForce = math.huge
pris.Attachment0 = attach1
pris.Attachment1 = attach0
pris.Parent = script.Parent

local up = true
pris.Velocity = speed
attach1.CFrame = finish.CFrame

start.Touched:Connect(function(hit)
    if (hit == script.Parent and not up) then
        up = true
        pris.Velocity = speed
        attach1.CFrame = finish.CFrame
    end
end)

finish.Touched:Connect(function(hit)
    if (hit == script.Parent and up) then
        up = false
        pris.Velocity = speed
        attach1.CFrame = start.CFrame
    end
end)

--156.314, 4701.603, 402.024 Start Position
--157.314, 4801.603, 402.024 Finish Position

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Why are you setting the PrismaticConstraint with a script? You can just add it in the Model > Constraints tab in Studio and you can use the Move and Rotate tools to align it properly.
You can just set the Velocity in the Properties window. In the script you just change the TargetPosition instead of setting a CFrame (I’ve never seen it done that way).

The issue you’re script is having is that you’ve set the Attachments to the centers of each of the items (script.Parent and game.Workspace.Terrain), so each one is not aligned to each other and the Part tries to move to the Terrain’s alignment. Use the manual Studio way, it’s soooo much easier.

1 Like

idk what you mean vy TargetPosition im new to coding so idk alot yet

Have a look at this:
https://www.roblox.com/library/7645980152/PlatformModel
I didn’t use any script to build it or set up the PrismaticConstraint. I just did them manually by clicking on the Constraint toolbar in the Model tab, then select PrismaticConstraint from the drop down menu. The first Part you click on will have the Attachment in it as well as the PrismaticConstraint, the second click should be on the Terrain or another Anchored Part.
Click the PrismaticConstriant then look at the Properties. You need to set the Force fairly high and the speed in studs per second.
Then to move it just change the TargetPosition using your script. If you use Studio to move the Part where it needs to be for the start and end Positions you can find out each end’s TargetPosition and use those for your script.
You’ll see the script that I used in the platform model I provided.