Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

3 comments

0

http://wiki.roblox.com/index.php?title=API:Class/Tool/Activated this event does not return mouse as in Activated:connect(function(mouse)

0

also use :Connect

0

try: local mouse = plr:GetMouse()

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.