I made a gun that shoots. It works, but it doesnt show the beam/bullet. Can someone help me? thanks!

script:

local isincar = false
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer

mouse.Button1Down:Connect(function()
	local h = script.Parent:WaitForChild("cAr").Value.Parent.Parent.Body.lala
	local ray = Ray.new(h.CFrame.p, (mouse.Hit.p - h.CFrame.p).unit * 300)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
		local b = Instance.new("Part")
		b.BrickColor = BrickColor.new("Bright yellow")
b.FormFactor = "Custom"
b.Material = "Plastic"
b.Transparency = 0
b.Anchored = true
b.Locked = true
b.CanCollide = false
local distance = (h.CFrame.p - position).magnitude
b.Size = Vector3.new(0.3, 0.3, distance)
b.CFrame = CFrame.new(h.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(b, 0.1)

if part then
	local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				humanoid:TakeDamage(30)
			end
		end
end)

4 comments

0

FormFactor is deprecated. So is CFrame.p. Use CFrame.Position

0

didnt work.

0

In between lines 19 and 20 set the parent to workspace lol

0

umg thx!!!!111!!!!111!!