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
http://wiki.roblox.com/index.php?title=API:Class/Tool/Activated this event does not return mouse as in Activated:connect(function(mouse)
also use :Connect
try: local mouse = plr:GetMouse()