Raycast laser is very delayed when put into a tool

  1. What do you want to achieve? The raycast laser reacts instantly like how it does in the world while it is put into a tool.

  2. What is the issue? As you can see here, the laser in the workspace reacts instantly as it should.

For testing, I put the laser part in the tool and welded it with a motor6d to the handle, but for some reason it’s very delayed, and I’m not quite sure why.

This is the lasers code, it’s just a simple Raycast that’s firing with a heartbeat, how can I fix this issue?

local Part = script.Parent
local Attachment1 = Part.Attachment1
local Attachment2 = Part.Attachment0
local RunService = game:GetService("RunService")

Attachment1.Position = Attachment2.CFrame.LookVector * 500


RunService.Heartbeat:Connect(function()
	local result = workspace:Raycast(Part.Position, Part.CFrame.LookVector * 500)
	if result then
		Attachment1.WorldPosition = Vector3.new(result.Position.X, result.Position.Y, result.Position.Z)
	else
		Attachment1.Position = Attachment2.CFrame.LookVector * 500
	end
end)

I suggest putting the Raycast in an Event for all players to replicate off of from a LocalScript using OnClientEvent (make sure it doesn’t replicate to the player with the gun)—
then also put the function you shown into a “RenderStepped” function in the players StarterCharacterScripts with a LocalScript so it has the best client behavior and no delay. Sadly that doesn’t fix the delay the other players will be able to see.

If I’m not mistaken, if other players still see the delay then there doesn’t seem much of a point, I can figure out something but If It still delays then that wouldn’t be good.

Maybe you could just make a LocalScript in every players StarterCharacterScripts that makes the laser function you shown be completely only called from every players LocalScript— That would be very messy and probably buggy, but that’s really the only solution I could think of that wouldn’t cause any delay on other players screens.

I see, I’ll figure out something thanks :slight_smile: