Inconsistent Client and Server Part Position

I’ve been attempting to figure out how to get a part to change its size and position at the same time while applying physical effects (eg. pushing parts aside). I’ve eventually settled for using a prismatic constraint to generate those physical effects and move the part to its new position. To adjust size, I used the lerp vector3 method. This doesn’t work very well when I’m testing through the client, but works pretty well in the server.

I haven’t ever encountered an issue where the client’s view is not consistent with the server’s so I’m not entirely sure where to start searching for problems. Especially when, in this file, there are no local scripts to be running anything client-specific. Does anyone know any common reasons why this would happen and how I’d go about making the client more accurately reflect the server?

1 Like

Hey!

Not sure why this is happening exactly but have you set the NetworkOwnership on the part?

I have last night, actually. I don’t think I did it right, though, since I had just learnt about it and all it did was make the scaling laggy. Is there a way I should be thinking about this?

1 Like

Still not sure why this is happening! However I have a theory, in the client the part isnt moving position, but in the server you can see it move to the right.

My guess is that you’re using 2 different scripts? Or that the bottom part is unanchored as well.

All parts that you see are unanchored. The part on the bottom (ie. the platform) is the only one with a script. That script in question is controlling a prismatic constraint that moves the platform and changes the size. It does this by switching the TargetPosition property of the prismatic constraint, using a while loop to stall the script until the platform reaches the position, and continuing on. In that while loop, I used a lerp vector3 method to change the size.

local platform = script.Parent -- This is the scaling part
local constraint = platform.Parent.ConstraintPoint.PrismaticConstraint

-- Testing variables at the moment
local largeSize = Vector3.new(8, 1, 8)
local smallSize = Vector3.new(4, 1, 8)

local function resize(size1)

    -- Size changing function

	local size0 = platform.Size
	local deltaX = math.abs(constraint.CurrentPosition - constraint.TargetPosition)
	
	while math.abs(constraint.CurrentPosition - constraint.TargetPosition) >= 0.001 do
		platform.Size = size0:Lerp(
			size1, 
			1 - math.abs(constraint.CurrentPosition - constraint.TargetPosition) / deltaX)
		task.wait()
	end
end

-- Make part loop between small and large
while true do
	constraint.TargetPosition = 0
	resize(smallSize)
	constraint.TargetPo​sition = 2
	resize(largeSize)
end

Is it bad that the bottom part is unanchored? Because I left it unanchored so that the prismatic constraint can actually do its job.