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:
-
What do you want to achieve?
Client side not freezing when someone seats at the vehicle (in this case, a train) -
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). -
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
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)