This is my first post on the DevForum, apologies for any mistakes, or lack of details.
I made a PrismaticConstraint based elevator for a cart ride, but when the player sits on the cart, and starts the elevator, it struggles to move. However, when there’s no cart on it, it works perfectly fine.
Video of elevator shaking problem
I believe the problem might be related to network ownership, however, I’m not entirely sure, and I do not know what steps to take, to fix it.
The issue here is the Network Ownership. Since the Client has the Network Ownership over the cart, but the Server over the Elevator, the Elevator struggles to move. You can notice it works once the player leaves the cart since the Network Ownership over the cart is then given to the Server. A way to fix it is to set the Network Ownership of the Elevator to the client temporarily. Otherwise you need to change the way the elevator works and use a different Service instead of Physics simulation.
In my post, I wrote “but when the player sits on the cart, and starts the elevator”. I forgot to clarify that it seems to happen only when the player is sitting in the cart.
Yeah, the issue is what @ShaShxa said.
here’s a way to fix it (this also prevents exploiters from being able to teleport their cart anywhere):
-- put this at the bottom of ur seatmanager script
Seat_1:GetPropertyChangedSignal("Occupant"):Connect(function()
for _,v in pairs(model:GetDescendants()) do
if not v:IsA("BasePart") or v.Anchored then continue end
v:SetNetworkOwner(nil)
end
end)
Seat_2:GetPropertyChangedSignal("Occupant"):Connect(function()
for _,v in pairs(model:GetDescendants()) do
if not v:IsA("BasePart") or v.Anchored then continue end
v:SetNetworkOwner(nil)
end
end)
Thanks, this worked to fix the elevator problem. However, after adding this code to the cart, I noticed that there’s a noticeable delay when turning the cart on and changing the speed. Is there any way to fix this? I’m aware this is a side effect of the network ownership change, but I want to know if there’s a way to fix both problems.
(White cart is without the code, black is with the code)
Yeah, but its kind of more complicated to do. First off, remove the code i gave you. Then you will have to get the current cart(s) on the elevator, when the button is pressed, and set their network ownership to the server when the elevator is going up/down, when it stopped, set it back to the player. (Do note that this is more complicated to do, and i cannot give you an example because i have no idea how your game will manage the spawning of the carts, etc…)
P.S: This will also allow exploiters to teleport their carts anywhere.