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

I don't Understand my output error about mouse can I have some help?

Asked by
Volt3Z 40
7 years ago

Hi, I am making a gun script and i want to define the mouse but when i play and click it says: Players.Player1.Backpack.Tool.Folder.CoreScript:22: attempt to index local 'mouse' (a nil value)

and this is the script:

--Variables--
local plr = game.Players.LocalPlayer
local tool = script.Parent.Parent
local hole = tool.Hole
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
--Events
tool.Equipped:connect(function()
    tool.Activated:connect(function(mouse)
        if debounce then
            --Anti-Spamming--
            debounce = false

            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)

            if allowtracing.Value == true then

                --THE PART--                

                local trace = Instance.new("Part",workspace)                
                trace.Material = Enum.Material.Plastic
                trace.BrickColor = plr.TeamColor
                trace.CanCollide = false
                trace.Transparency = 0.5
                trace.Anchored = true

                --Direction--

                local distance = (hole.CFrame.p - position).magnitude               
                trace.Size = Vector3.new(0.2,0.2, distance) 
                trace.CFrame = CFrame.new (hole.CFrame.p, position) * CFrame.new(0,0 -distance/2)       

                --remove trace--

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

            end

            --DAMAGE--

            if hit then
                local humanoid = hit.Parent:FindFirstChild("Humanoid")
                if humanoid then
                    if hit.Name == "Head" then
                        humanoid:TakeDamage(dmg.Value*2)

                    else

                        humanoid:TakeDamage(dmg.Value)

                    end
                end
            end

            wait(cooldown.Value)
            debounce = true

        end
    end)
end)

can someone help me plz?

0
http://wiki.roblox.com/index.php?title=API:Class/Tool/Activated this event does not return mouse as in Activated:connect(function(mouse) Programical 653 — 7y
0
also use :Connect Programical 653 — 7y
0
try: local mouse = plr:GetMouse() Programical 653 — 7y

1 answer

Log in to vote
0
Answered by 6 years ago

This will work

--Variables--
local plr = game.Players.LocalPlayer
local tool = script.Parent.Parent
local hole = tool.Hole
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 mouse  =plr:GetMouse()
--Events
tool.Equipped:connect(function()
    tool.Activated:connect(function()
        if debounce then
            --Anti-Spamming--
            debounce = false

            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)

            if allowtracing.Value == true then

                --THE PART--                

                local trace = Instance.new("Part",workspace)                
                trace.Material = Enum.Material.Plastic
                trace.BrickColor = plr.TeamColor
                trace.CanCollide = false
                trace.Transparency = 0.5
                trace.Anchored = true

                --Direction--

                local distance = (hole.CFrame.p - position).magnitude               
                trace.Size = Vector3.new(0.2,0.2, distance) 
                trace.CFrame = CFrame.new (hole.CFrame.p, position) * CFrame.new(0,0 -distance/2)       

                --remove trace--

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

            end

            --DAMAGE--

            if hit then
                local humanoid = hit.Parent:FindFirstChild("Humanoid")
                if humanoid then
                    if hit.Name == "Head" then
                        humanoid:TakeDamage(dmg.Value*2)

                    else

                        humanoid:TakeDamage(dmg.Value)

                    end
                end
            end

            wait(cooldown.Value)
            debounce = true

        end
    end)
end)

Ad

Answer this question