Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

HELP!! My ray-casting bullets collide against each-other! Please help?

Asked by 6 years ago
Edited 6 years ago

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)

0
Have you tried using and "if" statement? TinyScripter 70 — 6y
0
How would I use that in this script? Unkn0wn_Species 20 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Change the debris' delay to 0.1 or 0.01, in that way, it'll get removed immediately after the transparency has been set to 0.

Ad

Answer this question