I just made a gun and when I move + shoot the tracer is super delayed and nowhere near my barrel. But when I am standing still, it is fine. I have no idea how to fix this.
https://gyazo.com/19c87a889fddaa6c22cbd594b1969a97
here are my scripts:
--LOCAL
if game.Players.LocalPlayer then Player = game.Players.LocalPlayer end
local mouse = Player:GetMouse()
local tool = script.Parent
local event = script.Parent.RemoteEvent
local characterParts = Player.Character:GetDescendants()
activated = false
DB = false
tool.Activated:Connect(function()
activated = true
end)
tool.Deactivated:Connect(function()
activated = false
end)
mouse.Button1Down:Connect(function()
local position = mouse.Hit.p
if activated == true and position and DB == false then
DB = true
event:FireServer(position, characterParts)
wait(.1)
DB = false
end
end)
--SERVER
local event = script.Parent.RemoteEvent
local hole = script.Parent.hole
event.OnServerEvent:Connect(function(player, position, characterParts)
local ignore = script.Parent:GetDescendants()
for key, value in pairs(characterParts) do --Put all of the character parts into the ignore table.
table.insert(ignore, value)
end
local ray = Ray.new(hole.Position, (position - hole.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignore)
if part == nil then return end --if no part then stop
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(10)
end
local marker = Instance.new("Part", workspace)
marker.BrickColor = BrickColor.new("Bright yellow")
marker.CanCollide = false
marker.Anchored = true
marker.TopSurface = "SmoothNoOutlines"
marker.BottomSurface = "SmoothNoOutlines"
marker.Material = Enum.Material.Neon
local distance = (hole.Position - position).magnitude
marker.Size = Vector3.new(0.05, 0.05, distance)
marker.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(marker, .1)
end)
