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

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

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

3 comments

0

If you're using a script then that's the problem, you can only use it in local scripts

0

@TheNINJA152 If I Click on a player will it take damage on it?

0

No. You have to use remote events.

1 answer

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

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