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

Enemy Attack script not working! Player:GetMouse() erroring! (?)

I'm making this script in a sword, and it's supposed to kill the enemy when you click on it with the sword equipped.

The script:

script.Parent.Activated:Connect(function()
	local Mouse = game.Players.LocalPlayer:GetMouse()
	local Target = Mouse.Target
	if Target == game.Workspace.Health then
		game.Workspace.Health.Humanoid.Health = game.Workspace.Health.Humanoid.Health - 10
	end
end)

In the output, it gives me this error message:

  17:45:49.016 Players.charizardstar87.Backpack.ClassicSword.Script:2: attempt to index nil with 'GetMouse'

1 answer

✓ Accepted answer

Appears you’re trying to use LocalPlayer in a server script. Reason you can’t use a local script for this is because it would only show up for you. In this case, you’d need a remote since GetMouse() only works for a local script. Also, humanoid goes before health.

1 comment

0

Oh, you're right, lol thanks

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