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

Can you please help me fix this error: "This Mouse is no longer active"?

Asked by 6 years ago
--//Local Script Inside folder
--//Variables
local plr = game.Players.LocalPlayer
local tool = script.Parent
local hole = tool.Bullet
local handle = tool.Handle
local debounce = true
local config = tool.Config
local range = config.Range
local dmg = config.Damage
local coolDown = config.CoolDown
local clips = config.Clips
local ammo = config.Ammo
local maxAmmo = config.MaxAmmo
local allowTracing = config.AllowTracing
local mousea = plr:GetMouse()
local mb1down = false
local flash = script.Parent.flash
local da = flash.da
local db = flash.db

--//Events
tool.Equipped:connect(function(mouse)
    allowTracing.Value = true
    mousea.Button1Down:connect(function()
        if mb1down == false then
        local mb1down = true
        while mb1down == true do
        wait()
        if debounce == true then
            --//something..
            mouse.Button1Up:connect(function()
                mb1down = false
            end)
            --//Doesn't allow spamming
            debounce = false
            --//Ray Get, Set
            local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
            local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)

            --//Bullet Tracing
            if allowTracing.Value == true then
                --//Make part
                local trace = Instance.new("Part", workspace)
                trace.Material = Enum.Material.Neon
                trace.BrickColor = BrickColor.new("New Yeller")
                trace.CanCollide = false
                trace.Anchored = true
                trace.Transparency = 0.7
                da.Transparency = 0
                db.Transparency = 0     
                flash.flash.Enabled = true
                script.Parent.Sound:Play()

                --//Show Direction
                local distance = (hole.CFrame.p - position).magnitude
                trace.Size = Vector3.new(0.05, 0.05, 0.7)
                local it = math.random()*0.5
                local n = math.random(0,1)
                if n==0 then it=it*-1 end
                trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(it, 0, -distance/2)

                --//Remove debris
                game:GetService("Debris"):AddItem(trace, 0.1)
                --//Hit Detection

                if hit then
                    local humanoid =  hit.Parent:FindFirstChild("Humanoid")
                    if humanoid then
                        if hit.Name == "Head" then
                            --//Double damage on headshots
                            humanoid:TakeDamage(dmg.Value*1.5)
                        else
                            --//Normal Damage on body shots
                            humanoid:TakeDamage(dmg.Value)
                        end
                    end
                end
            end
            wait(coolDown.Value)
            da.Transparency = 1
            db.Transparency = 1
            flash.flash.Enabled = false
            script.Parent.Sound:Pause()
            debounce = true
        end
        end
        end
    end)
end)

tool.Unequipped:connect(function()
    allowTracing.Value = true
end)

So when I equip the tool then unequip it then equip it again and then try to shoot it, it sais: This Mouse is no longer active. (Line 38)

Answer this question