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

why Does My Script telling that it attempted to index nil with "GetMouse()"?

Asked by 4 years ago

So i am making a gun (I made 1 post about it) that when your clicking on the player It Will take damage.

heres the script:

wait(3)
local mouse = game.Players.LocalPlayer:GetMouse() -- Cant get mouse
local Handle = script.Parent.Handle
local Gun = script.Parent
local ShootSound = script.Parent.Handle.Shoot
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
Gun.Activated:Connect(function()
    mouse.Button1Down:Connect(function()
        if mouse.target.Parent:FindFirstChild("Humanoid").Parent ~=  game.Players.LocalPlayer.Name then
            Humanoid:TakeDamage(20)
            ShootSound:Play()
        else
            ShootSound:Play()   
        end
    end)
end)

Now The problem Is That It says it cant index nil with getmouse() Is there any way i can fix it?

thanks

/HKprogram

0
If you're using a script then that's the problem, you can only use it in local scripts TheNINJA152 85 — 4y
0
@TheNINJA152 If I Click on a player will it take damage on it? HKprogram 48 — 4y
0
No. You have to use remote events. Dovydas1118 1495 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

hm.. well... first, the code should be on a local script second, try doing some waits

--Add this on the start (replace the wait(3) with this code)
wait(3)
repeat wait() until game.Players
repeat wait() until game.Players.LocalPlayer

and so that should work, if not, then try to use prints to see the problem

Ad

Answer this question