I'm making a ray-casting gun, it's actually a Dual weapon. I have my scripts and the gun and everything needed, my only issue is the bullets collide together, but don't collide with anything else, I want the bullets to stop hitting each-other so you can fire as fast as you can press L-Mouse, eventually I will want this to be changed to something with a wait(2) so Autoclickers won't work on the gun. Help would be greatly appreciated, thanks for your time.
(Please note i'm studying scripting from http://wiki.roblox.com and youtube. I'm only a beginner too, and this is the best I can do at the moment.
LocalScript
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
tool.Equipped:connect(function(mouse)
print("Tool Equipped")
local debounce = false
mouse.Button1Down:connect(function(hit)
if not debounce then
debounce = true
print("Mouse pressed!")
local ray = Ray.new(tool.BulletExit.CFrame.p,(mouse.Hit.p - tool.BulletExit.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = player.TeamColor
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (tool.BulletExit.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(tool.BulletExit.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
beam.Transparency = 0
wait(.01)
beam.Transparency = .2
wait(.01)
beam.Transparency = .4
wait(.01)
beam.Transparency = .6
wait(.01)
beam.Transparency = .8
wait(.01)
beam.Transparency = 1
game:GetService("Debris"):AddItem(beam, .2)
wait()
debounce = false
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(5)
end
end
end
end)
end)
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
tool.Equipped:connect(function(mouse)
print("Tool Equipped")
local debounce = false
mouse.Button1Down:connect(function(hit)
if not debounce then
debounce = true
print("Mouse pressed!")
local ray = Ray.new(tool.BulletExit2.CFrame.p,(mouse.Hit.p - tool.BulletExit2.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = player.TeamColor
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (tool.BulletExit2.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(tool.BulletExit2.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
beam.Transparency = 0
wait(.01)
beam.Transparency = .2
wait(.01)
beam.Transparency = .4
wait(.01)
beam.Transparency = .6
wait(.01)
beam.Transparency = .8
wait(.01)
beam.Transparency = 1
game:GetService("Debris"):AddItem(beam, .2)
wait()
debounce = false
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(5)
end
end
end
end)
end)

3 comments
Have you tried using and "if" statement?
use the findraywithingorlist http://wiki.roblox.com/index.php?title=API:Class/Workspace/FindPartOnRayWithIgnoreList
How would I use that in this script?