I am making a raycasting gun and the issue I am having is when the player is moving the bullet is delayed and it doesn’t come out of the barrel instead it shoots from where the position of the barrel was a second ago. How can I speed it up so it is instant.
robloxapp-20210508-0642593.wmv (1.7 MB)
remote.OnServerEvent:Connect(function(player, position)
local shootPart = tool.Parts:WaitForChild("Barrel")
local origin = shootPart.Position
local direction = (position - origin).Unit
local result = Workspace:Raycast(shootPart.Position, direction*300)
local intersection = result and result.Position or origin + direction*300
local distance = (origin - intersection).Magnitude
-- Creating Ray --
local bullet_clone = ServerStorage.Bullet:Clone()
bullet_clone.Size = Vector3.new(0.1, 0.1, distance)
bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
bullet_clone.Parent = Workspace