I have a simple drag system where players can drag models with anchored parts around. It works well but the issue I have is with replication.
When a player is dragging something I only replicate it a few times a second as lots of players will be dragging models at once.
If a client is dragging a part around quickly it slightly rubber bands back to where it was a moment ago as the server position was sent back to the client.
So my question is can I somehow stop the player moving a model from getting position updates from the server.
Thanks
EDIT:
Here is the code:
Client:
local UserInputService = game:GetService("UserInputService")
local workspace = game:GetService("Workspace")
local camera = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local handleInteractionEvent = game:GetService("ReplicatedStorage"):WaitForChild("clientInteraction")
function GetHighestParent(part)
if part.Parent == workspace then
return part
end
return GetHighestParent(part.Parent)
end
function clampPlayerReach(playerVector,dragVector,num)
local x = math.clamp(dragVector.X, playerVector.X-num,playerVector.X+num)
local y = math.clamp(dragVector.Y, playerVector.Y-num,playerVector.Y+num)
local z = math.clamp(dragVector.Z, playerVector.Z-num,playerVector.Z+num)
return Vector3.new(x,y,z)
end
local lastReplication = tick();
local function handelDragReplication(model,loc)
local delta = tick()-lastReplication
if(delta >= 0.25) then
handleInteractionEvent:FireServer("posrep",model, loc)
lastReplication = tick()
end
end
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local target = GetHighestParent(mouse.Target)
local canGrab = target:FindFirstChild('canGrab')
if(canGrab and canGrab.Value) then
mouse.TargetFilter = target
repeat
if(mouse.Target) then --If the mouse isn't targeting a part igonre
local loc = clampPlayerReach(Character.PrimaryPart.Position,mouse.Hit.Position, 50)
target:MoveTo(loc)
handelDragReplication(target, loc)
end
wait()
until input.UserInputState == Enum.UserInputState.End
mouse.TargetFilter = nil;
end
end
end
)
Server side:
local handleInteractionEvent = game:GetService("ReplicatedStorage"):WaitForChild("clientInteraction")
local TweenService = game:GetService("TweenService")
local function handelPosRep(model, data)
model:MoveTo(data)
end
local function handleCall(player, command, model, data)
if(command == "flip") then
--Ignore
elseif(command == "posrep") then
handelPosRep(model, data)
end
end
-- Connect function to event
handleInteractionEvent.OnServerEvent:Connect(handleCall)
I also uploaded a place with this code: here
It seems a bit less of an issue in the place compared to in studio but its still there. My worry is that latency plays a part in how bad it is.