Syncing client and server

When you mine a block, it destroys it on the client, and then fires to server, so server does checks and then does the serverside delete there. It then creates the entity (from the server) and then the client detects when entity has been added and handles all the movement, etc. However my problem is there is a large gap between block being destroyed and entity created
ezgif.com-gif-maker (80)
Called when block is destroyed successfully on the server

--// Create entity
function EntityManager.Create(player, entity, source)
	local Entity = Tools:FindFirstChild(entity)
	if not Entity then return end
	
	local Handle = Entity:FindFirstChild("Handle")
	if not Handle then return end
	
	local NewEntity = Handle:Clone()
	
	local EntityModel = ConvertToModel(NewEntity)
	
	EntityModel.Name = entity
	
	-- Set CFrame
	EntityModel:SetPrimaryPartCFrame(CFrame.new(
		source.Position.X + math.random(-1, 1),
		source.Position.Y,
		source.Position.Z + math.random(-1, 1)
		)
	)
	
	EntityModel.PrimaryPart.Anchored = true
	
	CreateNewPrimaryPart(EntityModel) -- Need a seperate PrimaryPart for animating
	
	EntityModel.Parent = Entities
	
	CollectionService:AddTag(EntityModel, player) -- Add player tag to entity (so we know who owns what item)
	
	Debris:AddItem(EntityModel, DespawnTime) -- Add time, with despawn time
end
1 Like

Perhaps you could do the same thing you did with the breaking of blocks, and simply create a fake entity then replicate it if its good

For both the block breaking and entity creation you would also have to deal with the case in which the request was rejected by the server, where you could just replace the block or delete the entity

Only way server could reject block breaking is if the client is using exploits to pass invalid arguments to the server, in which case that’s on the client for using exploits and not my job to replace their blocks if they wanna use sketchy programs.

As for creating entity on the client, I don’t think that would make much sense, as you’d have an entity created on the client, that’d appear in a random position, and then it’d disappear and another entity would appear in a separate random position (entity created from the server)

You would create the entity in the proper position firstly on the client that broke the block, then replicate it to only the other players

Create the entity on the client first, check everything else on the server, if it’s good, send a remote event back to delete the entity on the client and create the entity on the server.

That’s still not very efficient. The server creates it in a random position. This would result in it being in a random position on the client, then deleted and spawned back in on the server in another random position

Send the CFrame to the server and change the CFrame of the entity?