Hello, I am working on making a gun.
I've been getting the error "Attempt to index local 'mouse' (a nil value)" when I click
I got the mouse through a remote event so I could use a script for everyone to see the bullet. Filtering is disabled.
Local script:
local player = game:GetService("Players").LocalPlayer --Gets the player
local mouse = player:GetMouse() //Gets the mouse
mouse.Button1Down:Connect(function()
script.Parent.GunRemote:FireServer(mouse, player) --Fires the server with variables "mouse" and "player"
print("Fired") -- Debug
end)
Script:
script.Parent.Parent.Gun.GunRemote.OnServerEvent:connect(function(plr, mouse, player)
local gun = script.Parent
local debounce = false
print("2") --debug
if debounce == true then return end
debounce = true
local ray = Ray.new(gun.CFrame.p, (mouse.Hit.p - gun.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Bright red")
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (gun.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(gun.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
beam.Touched:connect(function(who)
local explosion = Instance.new("Explosion")
explosion.Position = mouse.Hit.p
explosion.BlastPressure = 1000
explosion.BlastRadius = 1.5
explosion.Parent = workspace
end)
wait(1)
debounce = false
print("debounce") --debug
end)
Any help is apreciated.

2 comments
On line 2 in the local script, you are using "//" instead of "--".
Not sure if thats the problem but try typing "Connect" with capital C in line 23. Try maybe using "local mouse = plr.GetMouse (). I am not the best in Lua but hope I helped somehow.