I’m trying to make a gun that when you click (shoot) a kinda like laser comes out of the gun and highlights where you have clicked. My solution to this was to make a part(laser) that comes out of the gun. but no matter what I do the part never connects with the gun.
local i = 0
gun.Anchored = false
tool.Equipped:Connect(function(Mouse)
gui.Enabled = true
usr.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
reload = true
gui.TextLabel.Text = “Reloading…”
wait(2)
i = 0
gui.TextLabel.Text = “15/15”
reload = false
end
end)
Mouse.Button1Down:Connect(function()
if i < 15 and reload == false then
local tracer = Instance.new("Part")
local bullets = Instance.new("Part")
local x2 = mouse.Hit.Position.X
local y2 = mouse.Hit.Position.Y
local z2 = mouse.Hit.Position.Z
tracer.Size = Vector3.new(math.abs(gun.Position.X-x2), 1, 2)
print(tracer.Size)
tracer.Position = Vector3.new(x2, y2, z2)
tracer.Parent = game.Workspace
bullets.Size = Vector3.new(1, 1, 1)
bullets.Anchored = true
bullets.CanCollide = false
bullets.CFrame = CFrame.new(x2, y2, z2)
bullets.Parent = game.Workspace
i+= 1
gui.TextLabel.Text = 15-i.."/15"
wait()
bullets:Destroy()
end
end)
end)
tool.Unequipped:Connect(function()
gui.Enabled = false
end)