I’m trying to throw a grapple from my players position to a part using linearvelocity. I almost have everything working except for some reason my client thinks the grapple hook is a few studs farther than it actually is on the server. Here’s my code
local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
RS.Events.Shoot.OnServerEvent:Connect(function(player, RaycastResult, hook)
local target,position = RaycastResult["instance"],RaycastResult["position"]
local direction
local distance
print(target)
print(position)
target.Color = Color3.new(1,0,0)
local attouchment = Instance.new("Attachment",target)
attouchment.WorldPosition = position
attouchment.Name = "ATTOUCHMENT"
local LinearV = Instance.new("LinearVelocity", hook)
LinearV.Attachment0 = hook.ShootAttachment
hook:BreakJoints()
RunService.Stepped:Connect(function()
direction = (position - hook.ShootAttachment.WorldPosition).Unit
distance = (position - hook.ShootAttachment.WorldPosition).Magnitude
LinearV.VectorVelocity = direction * 80
print(distance)
if distance < 1 then
LinearV:Destroy()
attouchment.WorldPosition = position
hook.Anchored = true
end
end)
print("direction is")
print(direction)
end)
target is the part the raycast hit and position is the raycast hit position. If someone can figure out why the hook’s position on the client is different than on the server then let me know. It’s worth nothing that for some reason when I remove the if statement about the distance, the hook replicates normally.