Do lagging players have an impact on the functionality of PrismaticConstraints?

About
Hello, I am currently trying to create an automatic train for a subway game I work on together with others. I have built and scripted the train. I used PrismaticConstraints, set on Servo, to move the train along the rail by self. I also tried to achieve a smooth deceleration by this way.

repeat
	script.Parent.PrismaticConstraint.Speed = script.Parent.PrismaticConstraint.Speed - 0.4
	wait (0.001) -- Decrease speed by 0.4 every 0.001 seconds, until a speed less than 1 is achieved
until script.Parent.PrismaticConstraint.Speed < 1

script.Parent.PrismaticConstraint.Speed = 0 -- Fully stops the train.

The issue
My scripting is rather unconventional, as I am not really experienced in scripting.
When the train is driving, it will touch a brick on the track, firing an event to run these lines above. When I tested the train multiple times, with different computers on different graphic settings, the train always stopped at a different point, so I now am concerned that too many players, or players using lower tier computers could cause the train not stopping at the right point, so it decelerates at different speeds, causing the train to not stop at the right point.
Link to Game
Here is the link where you can test that place. The train should be behind you and leave the station after around a half minute. If you want to test it multiple times, you have to join a new game.

1 Like

How ROBLOX Physics works is that when it detects a player is close enough to a physically-intractable object (cancollide, unanchored, not sleeping), it will give it “network ownership”. This means the client will handle physics calculations and replicate it to the server.

If you want everyone to have a uniform experience, you can have the server perform all physics via Network Ownership. Simply set a part on the train that is moving with it via part:SetNetworkOwner(nil).

Furthermore, you should avoid using a brick in order to activate your motion acceleration/deceleration. Instead, you could just check the position of the train or the position of the prismatic constraint directly and save a physics interrupt.

3 Likes

Thank you so much, you helped me a lot.
I put this into every seat, and now everything works smoothly!

local VehicleSeat = script.Parent
 
VehicleSeat.Changed:Connect(function(prop)
	if prop == "Occupant" then
		local humanoid = VehicleSeat.Occupant
		if humanoid then
			local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
			if player then
				VehicleSeat:SetNetworkOwner(nil)
			end
		end
	end
end)