Hello, So I'm having a problem with my prismatic constraint elevator.
When I click the button for a floor it will calculate the target position for the prismatic constraint by firing a function that has a parameter called "obj" this obj parameter is the floor part I will be sending through to the function it then calculates the correct target position for the prismatic constraint by subtracting the prismatic constraints target position from the elevator platforms Y position then adding the obj parameters Y position (the elevator platform is the part that has the prismatic constraint in it, basically the main part)
This works perfectly when I'm already at a floor or the elevator has stopped BUT when I am already going down or up to a platform and click a button while in motion it misses the floor i want to go to but when it has stopped at the wrong position and i then press the button for the floor i missed again it then goes there perfectly fine...
I am very confused.
Code snippet for calculating target position:
function calcstud(obj)
local stud = ElevatorPlatform.Position.Y - ElevatorPlatform.PrismaticConstraint.TargetPosition+
obj.Position.Y
return stud
end
Code snippet for getting input from a button:
for i, child in ipairs(ButtonsGridGui:GetChildren()) do
if child:IsA("TextButton") then
child.MouseButton1Click:Connect(function()
print("Button "..child.Name.." was clicked")
local result = calcstud(Floors:FindFirstChild(child.Name))
ElevatorPlatform.PrismaticConstraint.TargetPosition = result
print(result)
end)
end
end
Some details about some of the stuff referenced in the code:
There is a group for all the floors each floor is just a part that the elevator goes up to
The elevator can have inf floors meaning I'm using a surface GUI with a scrolling frame and a UIGridLayout for buttons (there is a function for setting up buttons depending on amount of floors but that has nothing to do with the problem)
The buttons for each floor and the floors are numbered from 1 to whatever amount of floors you have, this means i can detect what button was pressed and find the floor by just searching in floor folder for the buttons name
Video of what's happening: https://streamable.com/2oo8za
Hopefully I can get some answers!

3 comments
https://www.roblox.com/games/7178302913/Elevator? If you wanna test the elevator
No idea what the problem is, just make it go to the position of whatever the selected floor is, yeah?
i can do that BUT if the y position of the elevator isn't 0 then it will miss the floor as the target pos is still 0 no matter what the y pos of the elevator platform