Event Part.NetworkOwnerChanged

I’m requesting an Event Part.NetworkOwnerChanged(Player newOwner, Player oldOwner) be added to the BasePart Class. Reason being, for a game of mine, I have the ownership of a vehicle set to a Player when it’s created so that they can control the vehicle smoothly with bodymovers. However, at some times when colliding with parts of the Track (at sharp angles), the ownership of the vehicle will randomly be given to the Server (nil), when this happens, my local scripts are unable to move the vehicle since the server doesn’t see the changes to the Body Movers.

Instead of using a while loop on the server to constantly check for a Network Ownership change, Id rather just have an event for when it changes, that way I can have it set the ownerships back to the Player. Also I can’t check in my client loop to see if the ownership was changed since the GetNeworkOwnership function is limited to server only.

Excuse the Lag, my computer I think was running low on memory


The network ownership changes when it hits the track at the bottom of the hill, and tries to move the ship to the Finish line, since the Server still sees a BodyPosition as trying to move it there.

11 Likes

This sounds like a bug that should never happen in the first place.

and it doesn’t sound like you’re doing either of those.

2 Likes

Yep, not doing either of those. @Khanovich

Also if it helps, I’ve noticed this bug since the Network Ownership stuff was added, I just didn’t know what was causing the Ship to freeze up at that time.

If you listen to the Changed event of the Part, there is actually an unscriptable internal property that you could possibly use to detect this.

local function onChanged(property)
	if property == "NetworkOwnershipRuleBool" then
		local isAuto = part:GetNetworkOwnershipAuto()
		if isAuto then
			print("The server is automating the Network Ownership of",part)
		else
			print("The Network Ownership of",part,"is being manually overridden.")
		end
		print("Current Owner:",part:GetNetworkOwner())
	end
end
--
part.Changed:connect(onChanged)
1 Like

The changed event wasn’t fired when the network ownership changed, or at least not with that property.

Thats odd.
Do you have code that might be accidentally setting the network ownership to nil?

There was only one spot where I used SetNetworkOwner and it is where I set the owner to the Player when the ship is spawned. I also have no calls to the SetNetworkOwnershipAuto function anywhere in the code.

1 Like

Heres another thing you could possibly try.

if part.CFrame:toObjectSpace(part:GetRenderCFrame()).p.magnitude > 0.5 then
	-- Tell the server to change the network ownership  with a remote event?
end

Well my Changed event on the server seems to be only looking at this property “NetworkIsSleeping” nothing else is being fired from the Changed Event.

It fires twice when ship is being created, and seems to fire each time the network ownership is changed, so I can probably use this to check for it.

Code I used to get print statements.
function GS:ShipChanged(property,newship,oplayer)
print("Changed ",property)
if property == “NetworkOwnershipRuleBool” and newship and newship:FindFirstChild(“Main”) then
local isAuto = newship.Main:GetNetworkOwnershipAuto()
if isAuto then
print(“The server is automating the Network Ownership of”,newship.Main)
else
print(“The Network Ownership of”,newship.Main,“is being manually overridden.”)
end
print(“Current Owner:”,newship.Main:GetNetworkOwner())
if newship.Main:GetNetworkOwner() ~= oplayer then
newship.Main:SetNetworkOwner(oplayer)
end
end
end

newship.Main.Changed:connect(function(prop) GS:ShipChanged(prop,newship,oplayer) end)

also how to format code on here? for some reason it wont accept my indents.

Well testing it out, it seems fire inconstantly, some times it gets it right away, other times it never fires, or it fires 2-4 seconds after the ownership is switched.

However, it is in fact manually being overridden by the server:

Wait you’re saying Manual network ownership somehow fails when you hit the track? That makes no sense to me. How easy is this to repro?

I’m not sure how simple of a repro I can make, but when I hit the Track pretty much straight on it manually sets the Ownership of my Ship to nil (or the server), about 60% of the time, depending on how I hit the Ramp.

Link to place?

However, let me first make a Track that it can be easily reproducible on.

if you want to try to reproduce it on the track I currently am, you will have to hit the “Find Servers” button on the right side of gui, and then hit the Join button (which is kind of hidden, currently going under GUI redesigning). Once in the new server you just need to “ready up” and the vote for the “Tunrac” track

Video of reproducing it:


In this video I have a while loop on wait(.1) that is fixing the ownership, but as you can see it fixes it too late, as the ship has already been launched into orbit.

Ok I made a pretty easy to reproduce track, Just do as posted above but vote for “TestTrack1”. To reproduce just keep driving straight into the Hills while boosting (spacebar). The faster you are going, the higher the chance it occurs. I also find it somewhat easier to reproduce if you drive on the track backwards on the smaller hill.
Edit: I also disabled the while loop that is trying to fix it, so you can notice it more. You can hit R to respawn the ship which will fix the ownership.

The only thing I can think of that could be causing it is a bad cframe being set to the BodyGyro, which orients the ship.

How do I make this game work in Start Server + Start Player? Once I got through the DataStore errors by publishing (It’s in an inactive place, so don’t worry) it won’t let me join a Race because the server ID is 0.

Does not have an ID
0
Does not have an ID
0

In the MatchMakingS module Script, you need to replace the placeId in the CreatePlaceAsync Function to a Place that can be copied by and is apart of the game. For example you can just upload the exact clone of the place to another place in the universe and allow it to be used as a template for CreatePlaceAsync (I have gotten around to replacing this with Reserved Servers yet).

Also you will probably need to copy these models and upload them so your game has access to them.



as long as you don’t vote for Tunrac or Lorizo you should be fine with just the TestTrack1 model.

Edit: actually does CreatePlaceAsync work in Studio, I can’t seem to get it to run either, I don’t normally test this game in Studio.

Hmmm, CreatePlaceAsync probably doesn’t because it would require us to be able to connect with a live server from Studio.

ok I made the Test track the Default Track, so all you need to do is hit “Ships” then “Test Ship”, don’t even need to take the Model.

So I have it spawning me now, but the ship won’t go forward. Is there like a “Go” button or am I missing something?