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

Can someone help me make a cooldown on my blaster pistol?

Asked by 6 years ago

So, i made a laser blaster and its kinds unbalanced because it doesnt has cooldown. so, i asked other people how and they said no, i tryed it myself but it failed. can you help me? the code:~~~~~~~~~~~~~~~~~ local tool = script.Parent local sound = tool:WaitForChild("Gunfire") local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse) print("Tool equipped!")

if script.Parent.Canshoot then

mouse.Button1Down:connect(function()
    print("Mouse pressed!")
    local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
    local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
    script.Parent.Shooting.Value = true

    local beam = Instance.new("Part", workspace)
    beam.BrickColor = BrickColor.new("Really red")
    beam.FormFactor = "Custom"
    beam.Material = "Neon"
    beam.Transparency = 0.5
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false

    local distance = (tool.Gun.CFrame.p - position).magnitude
    beam.Size = Vector3.new(0.3, 0.3, distance)
    beam.CFrame = CFrame.new(tool.Gun.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

    game:GetService("Debris"):AddItem(beam, 0.1)

    if script.Parent.Shooting.value then
                        script.Parent.Gunfire:Play()
                        script.Parent.Gun.PointLight.Enabled=true
                        wait(0.1)
                        script.Parent.Gun.PointLight.Enabled=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(22)


            end

        end
    end
end)

end) ~~~~~~~~~~~~~~~~~

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Like this

mouse.Button1Down:connect(function()
    if script.Parent.Canshoot.Value == true then
        script.Parent.Canshoot.Value = false
        --script
        wait(HowMuchToWait)
        script.Parent.Canshoot.Value = true
    end
end)
0
Fixed Shadowman670 -4 — 6y
0
Hi, i did it but at the end) it says : expected identifier, got ) Nonglolprogames -19 — 6y
0
this is the code, again Nonglolprogames -19 — 6y
0
its thge other ansewer VVVV Nonglolprogames -19 — 6y
0
i missed some script thats why Nonglolprogames -19 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
  local tool = script.Parent
local sound = tool:WaitForChild("Gunfire")
local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse)
    print("Tool equipped!")

    mouse.Button1Down:connect(function()
        print("Mouse pressed!")
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
        script.Parent.Shooting.Value = true

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Really red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.5
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Gun.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Gun.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

        game:GetService("Debris"):AddItem(beam, 0.1)

        if script.Parent.Shooting.value then
                            script.Parent.Gunfire:Play()
                            script.Parent.Gun.PointLight.Enabled=true
                            wait(0.1)
                            script.Parent.Gun.PointLight.Enabled=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(22)


                end

            end
        end
    end)
end)

Answer this question