I have been having issues with syncing projectiles that need to be seen by both players,
The goal is to have both players see the Projectile, however I want the player firing it to get the feedback of the projectile (Example: If a magic game has someone cast a fireball, they should see their fireball appear as it is a graphical effect, the actual fireball is not used for any hit-detection.
The way that I originally tried it was by having the client make an un-replicated version which the Server would then create later (offset accordingly for lag-compensation), once the server sends back that it was done, the client simply deletes their version
-- ClientSide Code
local someRemoteFunction --target whatever RemoteFunction you use for Projectile effect Graphics
function fireProjectile(projectile, position, direction)
local dummyProjectile = projectile:Clone()
dummyProjectile.Parent = workspace
dummyProjectile.AssemblyLinearVelocity = direction
local completeSyncedProjectile = someRemoteFunction:InvokeServer(projectile, position, direction, tick())
dummyProjectile:Destroy()
end
-- ServerSide Code
function someRemoteFunction.OnInvokeServer(player, projectile, position, direction, timeStamp)
local timeDiff = tick() - timeStamp
local projectile_True = projectile:Clone()
projectile_True.Parent = workspace
projectile_True.Position = position + (direction * timeDiff)
projectile_True.AssemblyLinearVelocity = direction
return projectile_True
end
But I feel like this could be done way better, is there any advice on whether this is being made overtly-complicated?