I've built my pistol and studied the Ray Casting are in ROBLOXwiki My only issue is that the bullets hit each other and stop, they're supposed to stop when they hit a terrain part or a wall, but not each other, or players, so they don't stop the player from walking but still take damage. How can I fix this. Help??
This LocalScript is using RayCasting for the bullets.
Here's the 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(2.5)
end
end
end
end)
end)
Thanks for your time
-Species
