Tracer doesn't wanna change size at all

i have this cool little shotgun, and it shoots!

it shoots 8 pellets, and i wanted them all to have tracers, so i added them!

it… works? Technically it does, but the part size is kind of breaking the thing
the bullet tracers use space alien mathemathics code to gain the proper size, but even space alien technology can break, i think

ShootEvent.OnServerEvent:Connect(function(player)
	local mossberg = player.Character:FindFirstChildOfClass("Tool")
	local damage = 11

	local PELLETS = 8
	local HORIZONTAL_SPREAD = {min = -0.2, max = 0.2}
	local VERTICAL_SPREAD = {min = -0.2, max = 0.2}
	local MAX_DISTANCE = 50

	local origin = mossberg:WaitForChild("Flash")

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = { player.Character }
	raycastParams.IgnoreWater = true
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude


	for pellet=1, PELLETS do
		local spreadX = HORIZONTAL_SPREAD.min + (math.random() * (HORIZONTAL_SPREAD.max - HORIZONTAL_SPREAD.min))
		local spreadY = VERTICAL_SPREAD.min + (math.random() * (VERTICAL_SPREAD.max - VERTICAL_SPREAD.min))

		local direction = (origin.CFrame.LookVector + Vector3.new(spreadX, spreadY)).Unit
		local displacement = direction * MAX_DISTANCE
		
		local result = workspace:Raycast(
			origin.Position, 
			displacement,
			raycastParams
		)

-- everything happens here!!!
		local tracer = Instance.new("Part")
		tracer.Parent = workspace
		tracer.Anchored = true
		tracer.CFrame = CFrame.lookAt(origin.Position, (origin.Position + displacement)) * CFrame.new(0,0, displacement)
		tracer.Size = Vector3.new(0.1, 0.1, displacement.Magnitude)
		tracer.Transparency = 0.6
		tracer.CanCollide = false
		
		tracer.Color = Color3.new(0.960784, 0.666667, 0.156863)



		if result ~= nil then
			print(result)
			local enemy = result.Instance.Parent:FindFirstChild("Humanoid")

			if enemy == game:GetService("Players"):GetPlayerFromCharacter(result.Instance.Parent) then continue end

			enemy:TakeDamage(damage)
			DamageGUIEvent:FireClient(player, damage, enemy)
		end
	end


end)

the results of that code are rather weird:

the part doesn’t wanna get smaller nor bigger and i don’t know why :frowning_face: :-1:

on this line:

tracer.CFrame = CFrame.lookAt(origin.Position, (origin.Position + displacement)) * CFrame.new(0,0, displacement)

this calculation isnt exactly right so instead try this:

tracer.CFrame = CFrame.lookAt(origin.Position + (Displacement / 2), origin.Position + Displacement)
1 Like

ah yeah that did the trick, thanks!!! :heart:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.