Hello there i’m having this tiny problem where the hitboxes lag behind
The red part is the part that is being positioned by the server
The white one is being handled by the client so it’s not lagging behind only the server one any help?
What should i do to sync it?
Server Script
function playerJoined(player: Player)
print("is this working")
player.CharacterAdded:Connect(function(character)
print("is this working")
local clone = helicopter:Clone()
local hitbox = raycastHitbox.new(clone)
local tempFilter = {}
hitbox.Visualizer = true
hitbox.DetectionMode = 1
hitbox:HitStart()
hitbox.OnHit:Connect(function(hit)
print(hit)
if hit:IsA("Part") or hit:IsA("MeshPart") then
if hit.Parent.Parent.Name == "Enemy" and hit.Parent.Parent:IsA("Folder") then
local char = hit.Parent
local humanoid = char:FindFirstChild("Humanoid")
if humanoid then
table.insert(tempFilter, char)
RaycastParamss.FilterDescendantsInstances = {table.unpack(tempFilter)}
hitbox.RaycastParams = RaycastParamss
hitbox:HitStop()
hitbox:HitStart()
humanoid:TakeDamage(10)
task.wait(.3)
for i,v in ipairs(tempFilter) do
if char == v then
table.remove(tempFilter,i)
RaycastParamss.FilterDescendantsInstances = {table.unpack(tempFilter)}
hitbox.RaycastParams = RaycastParamss
return
end
end
end
end
end
end)
clone.Parent = workspace
clone.Transparency = 0
local humanoid = character:WaitForChild("HumanoidRootPart")
clone.CFrame = humanoid.CFrame
RunService.Heartbeat:Connect(function()
local ping = player:GetNetworkPing()
if ping ~= 0 then
clone.CFrame = CFrame.new(humanoid.Position * ping) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
else
clone.CFrame = CFrame.new(humanoid.Position) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
end
end)
character.Humanoid.Died:Connect(function()
task.wait(3)
player:LoadCharacter()
end)
end)
player:LoadCharacter()
end
Local Script
local RunService = game:GetService("RunService")
local repStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RotationSpeed = 4
local character = script.Parent
local helicopter = repStorage:WaitForChild("Helicopter")
local clone = helicopter:Clone()
clone.Parent = character
local humanoid = character:WaitForChild("HumanoidRootPart")
clone.CFrame = humanoid.CFrame
RunService.Heartbeat:Connect(function()
clone.CFrame = CFrame.new(humanoid.Position) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
end)
For more info
i’m using heartbeat service to position the part in the server and also in the client