Raycast car, when player bumps into it, the car freezes on client but still is moving on server

when the player bumps into the car, the car’s model freezes and slides away on the client but not the server

CLIENT

SERVER

EDIT: heres a vidoe

not sure if this has to do with it but, I do have this code on the server
mainBody:SetNetworkOwner(nil)

anyone know the problem?

2 Likes

I’m going to take a guess and say it’s because you’re setting NetworkOwner to nil. If the logic that makes the car move is on the client, the car will move on the client but the effect will not replicate because they don’t have ownership over the car. Set the ownership to the client to see the code replicate (raycasts)

when I first start the game, the car’s ownership gets set to nil on the server and then the server script runs a module script to do the raycasting and stuff, and then when the player sits in the vehicle seat, the server script stops running the module script and the client then runs the same module

Yes but the networkOwnership is never set back to the player

wait wym by that?, how would I set it back

like this:
car:SetNetworkOwner(player)

yeah I do that when the player sits

	driverSeat.Changed:Connect(function(property)
		if driverSeat.Occupant then
			local player = players:GetPlayerFromCharacter(driverSeat.Occupant.Parent)
			
			if not player or not player.Character then return end
			for _, part in pairs(player.Character:GetChildren()) do
				if part:IsA('BasePart') then
					part.Massless = true
				end
			end
			
			mainBody:SetNetworkOwner(player)
		else
			mainBody:SetNetworkOwner(nil)
		end
	end)

What if you just don’t set it to nil? does it work?

nope, its still doing the same thing

In the video you sent, you’re never sitting in the seat

yeah and the car has a hard time updating on the cleint where it is on the server

Hm so not sure why you’re raycasting on the server, if the only time the car is actually moving is when someone (client) is driving it. it also looks like you’re pushing the car on the client so the location is different because of network ownership reasons. Thinking maybe it would be easier to remove the code that raycasts on the server and just do it on the client, then let roblox automatically set network ownership instead.

well I’m raycasting on the server so the car has a suspension to keep it up off the ground

You can do that on the client, and if you want just an idle stance you could anchor it at a set height

I dont wanna anchor it, then it would be stiff and not moveable by anything without the player

Do you want the car to be able to get pushed?

yeah and show that it has a suspension

Make sure the RootPriority of the base of the car is set to 1.

I tried that but it didnt seem to fix it

and I have another bug, do you know what might be causing it so float like this? also dont mind the debug parts

its floating above nothing and sliding away
image

Seems like an issue with replication. Is your raycast car being managed on the client, server, or both?