How do i fix the bullet teleporting when Position is greater than 50?

local BulletEvent = game:GetService('ReplicatedStorage').Events.BulletEvent
local Bullets = workspace
local RunService = game:GetService('RunService')
BulletEvent.OnClientEvent:Connect(function(Position,Muzzle,DebounceTime,Shoot)
	local Bullet = Instance.new('Part',Bullets)
	Bullet.Anchored = true
	Bullet.CanCollide = false
	Bullet.Color = Color3.new(1, 0.666667, 0)
	Bullet.Material = Enum.Material.Neon
	local Connection = RunService.PreRender:Connect(function()
		local Distance = math.clamp((Position-Muzzle.Position).Magnitude,0,50)
		Bullet.CFrame =  CFrame.new(Position,Muzzle.Position)*CFrame.new(0,0,-Distance/2)
		Bullet.Size = Vector3.new(0.1,0.1,Distance)
	end)
	local ClonedShoot = Shoot:Clone()
	ClonedShoot.Parent = Muzzle
	ClonedShoot:Play()
	task.wait(DebounceTime)
	Connection:Disconnect()
	Bullet:Destroy()
	task.wait(ClonedShoot.TimeLength-DebounceTime)
	ClonedShoot:Destroy()
end)

also, dont remove the math clamped distance, its important, when the Position is greater than 50 it looks like the bullet teleports.

What do you actually want to do? Do you want the bullet to be Destroyed or Teleport after position
50. Replace the 50000 with 50

This script has been taken from another Post. The post had a good explanation on how to create the shooting part (Its a module script)


local bullet = Instance.new("Part", workspace)
bullet.Size =  Vector3.new(0.06, 0.06, 4)
bullet.Anchored = true
bullet.CanCollide = false
bullet.Color = Color3.new(0, 0, 0)
bullet.Material = Enum.Material.Neon
bullet.Parent = game.Workspace
bullet.CFrame = CFrame.new(Vector3.new(origin.X, origin.Y+0.1, origin.Z), endposition)

local Loop

Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)

	local Hit = game.Workspace:Raycast(bullet.Position, bullet.CFrame.LookVector * velocity * 1.5)

	if Hit then
		if Hit.Instance.Parent:FindFirstChild("Humanoid") then
			--Handle Damage
			bullet:Destroy()
			Loop:Disconnect()
		else
			-- Hit a Wall
			bullet:Destroy()
			Loop:Disconnect()
		end
	end

	-- Position Thing
	bullet.CFrame *= CFrame.new(0,0, -velocity*(dt*60) )
	if (bullet.Position - origing).magnitude > 50000 then
		bullet:Destroy()
		Loop:Disconnect()
	end
end)

robloxapp-20250228-1619457.wmv (247.2 KB)
i mean the bullet looks like this when mouse pos distance is greater than the muzzle by 50 studs.

Try the code I gave it worked fine for me when I created a shooting game

Its destroys the bullets after 50000 , you can use 50

i dont want the bullets to be destroyed, i want the bullets to still show up even if the distance is greater than 50 but making the bullet not teleport

Yah just remove the Bullet:Destory() part in the script

but yours has a velocity and others, mine is just a line bullet. i cant use ur script tehn

ClonedShoot:Destroy()
What is this about?

its a sound for the gun when it shoots

Can you please specify: Line bullet. All bullets go in a line. The code which I gave also shoots it in the direction the player is facing.