Issue with NetworkOwnership, client side for passengers gets frozen inside vehicle

During the last few days, i have experienced lots of issues regarding NetworkOwnership, I will explain it in this post, and let’s see if someone can help with it. I don’t know if this is the correct category, but i think so. Let’s start:

  1. What do you want to achieve?
    Client side not freezing when someone seats at the vehicle (in this case, a train)

  2. What is the issue?
    Vehicle freezing for the client-side, concretely the passenger (who sits in the train). The train has 3 coaches. When the driver is located at the front, and changes direction to the rear cab, the players who sat in the rear coach will experience to be stuck, while the players who sat at other coaches are moving, aswell as the server-side.
    If you’re wondering how NetworkOwnership is set here, it’s exactly how it says in the docs (code below), in both cabins, front and rear, separate scripts (always server scripts).

  3. What solutions have you tried so far?
    I’ve tried to break welds in passenger seats when the driver changed from cabs, but that doesn’t work either if the passenger sits again, it remains stuck as usual.
    I’ve recently removed anchor from train engines, as that was causing NetworkOwnership API to fail, it doesn’t work either.

I could actually disable seats in that part of the train, but it wouldn’t be good. If someone can find a solution / knows how to solve this issue, please help me below. Thanks :slight_smile:

Seat.Changed:Connect(function(prop)
	if prop == "Occupant" then
		local humanoid = Seat.Occupant
		if humanoid then
			-- Get the player from the character
			local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
			if player then
				local success, error = pcall(function()
					Seat:SetNetworkOwner(player)
				end)
				if not success and error then
					warn(error)
					--retry by disabling engines anchor, if they were enabled (which they probably won't)
					for _, engine in ipairs(Engines) do
						if engine.Anchored then
							engine.Anchored = false
						end
					end
					local success, error = pcall(function()
						Seat:SetNetworkOwner(player)
					end)
					if not success and error then
						warn(error)
					end
				end
			end
		else
			-- Reset ownership when seat is unoccupied
			Seat:SetNetworkOwnershipAuto()
		end
	end
end)
1 Like

Network ownership works on an assembly, not individual parts. If you have a train that is connected together physically through welds and joints, it will be a single assembly, and setting the ownership of any part in that assembly will set the ownerships of the whole assembly to that player. The last player to sit down will have network ownership of the train at any given moment. If another player sits down and the driver’s client is attempting to apply forces to the train, those forces will be filtered as the driver is no longer the network owner of the train. To fix this, try only applying network ownership to the drivers seat and only to one player at a time.

2 Likes

hi, thanks for a response! NetworkOwnership is only assigned to the driver, as you can see. My question is, do I have to assign network ownership in one driver cab, or in both?

Is the script making it move from the client side?

yes, the train moves from the client-side. The Ownership is applied through a server script.

Please specify, what do you mean by “client side freezing”?

If your train is a single mechanism, you need to assign the ownership in just one place of your train.

A mechanism is a set of assemblies connected with constraints.
An assembly is a group of parts that have rigid joints with each other (Welds, WeldConstraints etc).

1 Like

the passenger sitting inside the train will hear the train sounds, but the train remains there, while in the server and for the other clients it moves

that worked! thank you so much!

1 Like

one more question,
do you know if the parts can be anchored after NetworkOwnership is applied?

I would like to “anchor” the train when doors are opened, if possible.

They can, but by doing so they can “forget” their network ownership, so you might want to reapply the network ownership after you unanchor.

wouldn’t re-applying the network ownership cause the train to freeze again?

I think it shouldn’t but I’m not 100% sure.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.