Line 23 is where the error comes in saying 'mouse is nil'. Go test it.
--//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
--//Doesn't allow spamming
debounce = false
--//Ray Get, Set
local ray = Ray.new(hole.CFrame.p (mouse.Hit.p - hole.CFrame.p*range.Value) --ERROR
local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
if allowTracing.Value == true then
--//Make "part
local trace = Instance.new("Part", workspace)
trace.Material = Enum.Material.Neon
trace.BrickColor = BrickColor.new("Orange")
trace.CanCollide = false
trace.Anchored = true
trace.Transparency = 0.5
--//Show 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 Debris
game:GetService("Debris"):AddItem(trace, 0.1)
end
--//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*2)
else
--//Normal damage on body shots
humanoid.TakeDamage(dmg.Value)
end
end
end
wait(coolDown.Value)
debounce = true
end
end)
end)
