Client and Server are seeing different things?

I have a script that drops a blue part from the sky, it uses a raycast to check the distance between the part and the distance between ground. Once it reaches a certain distance, the part will be anchored. Well it works fine, but for some reason the server and client are seeing different things. Notice how on the client the balls are up in the sky, while on the server its low on the ground.

CLIENT

SERVER

local RS = game.ReplicatedStorage
local debris = game.Debris
local powerupDrop = workspace.PowerupDrop

while wait(1) do
	local offset = Vector3.new(math.random(-500, 0), 300, math.random(-45, 45))

	local powerup = RS.Powerups.Freeze:Clone()
	powerup.Position = powerupDrop.Position + offset
	powerup.Parent = workspace
	debris:AddItem(powerup, 60)
	
	repeat 
		local rayOrigin = powerup.Position
		local rayDirection = Vector3.new(0, -300, 0)
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
	
		if raycastResult then
			print(powerup.Position.Y)
			distFromGround = (powerup.Position.Y - raycastResult.Position.Y)
			print(raycastResult.Instance.Name)
			print(distFromGround)
			wait()
		end
	until distFromGround <= 2
	powerup.Anchored = true
end
1 Like

My guess is that it’s something to do with replicating information to the client. This can be solved by many methods, like handling the raycast on the client or firing a remote to the client to position the object correctly on the client’s side.

2 Likes

Alright, I’ll try that, thanks.

Is this script a LocalScript or a ServerScript?

Server. I’ve fixed it by making it a local.

Wait. So clarify. Is the problem fixed? It being a LocalScript does not make sense

Yes It’s fixed, I’ve made it so that only the client can see the powerup. There is nothing on the server. When the client touches the ball I’ll fire a RemoteEvent.

Alright. Then mark your post as the Solution so other people know it is fixed.

Have a good day!

1 Like