I have a system that moves a hook to my cursor using a lerp that makes it move at constant velocity. I can set the speed I want it to go beforehand. The problem is, whenever my distance from the end goal is less than the speed, it will still work fine on the server but it won’t replicate to the client. The distance is simply defined as subtracting the two vector3’s of the end goal and starting position and just getting the magnitude. I have no idea what’s causing this it’s a very obscure issue.
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")
local IsShooting = false
local speed = 32
local function BreakJoints(part)
for _,child in part:GetJoints() do
child:Destroy()
end
end
RS.Events.Shoot.OnServerEvent:Connect(function(player, RaycastResult, hook)
IsShooting = true
local target,position = RaycastResult["instance"],RaycastResult["position"]
print(target)
print(position)
local HookHitAttachment = Instance.new("Attachment", target)
HookHitAttachment.Name = "HookHitPosition"
HookHitAttachment.WorldPosition = position
position = HookHitAttachment.WorldPosition
local targetCFrame = target.CFrame
local HookPos = hook.Position
print("hookpos is")
print(HookPos)
local distance = (HookPos-position).Magnitude
local inc = 0
hook.Anchored = true
BreakJoints(hook)
for i = 0, distance, speed do
print("forloop ran")
if IsShooting == false then
HookHitAttachment:Destroy()
break
end
--hook.CFrame = CFrame.lookAt(hook.Position,HookHitAttachment.WorldPosition) * CFrame.Angles(0,math.rad(180),0)
local progress = i/distance
if distance <= speed then
print("too close")
hook.Position = HookHitAttachment.WorldPosition
print(hook.Position)
print(HookHitAttachment.WorldPosition)
else
print("not too close")
hook.Position = HookPos:Lerp(HookHitAttachment.WorldPosition, progress)
end
RunService.Heartbeat:Wait()
inc += 1
if inc == math.ceil(distance/speed) then
print("distance is "..distance)
print("distance/speed is "..distance/speed)
hook.Position = HookHitAttachment.WorldPosition
print("p"..progress)
print("i is "..i)
print("inc is "..inc)
if progress == 0 then
print("uh oh")
end
--print("last time")
--local weld = Instance.new("WeldConstraint", target)
--weld.Part0 = hook
--weld.Part1 = target
--hook.Anchored = false
end
end
end)