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

mouse = player:GetMouse() nil value?

Im trying to get player's mouse position. But im getting ServerScriptService.DamagableManager:48: attempt to index local 'mouse' (a nil value) error

LocalScript that im trying to connect to Server Script:

local function onMousedClicked(actionName,inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then	
		CheckIfDamagable:InvokeServer()
		print("MouseClicked")
	end
end

server Script that im tring to get mouse info:



function CheckIfDamagableObject(player) 
	 local mouse = player:GetMouse()
		
	--Unrelated codes here

end


CheckIfDamagable.OnServerInvoke = CheckIfDamagableObject

1 answer

You cannot get mouse info from a non-local script.

I can't think of a reason that you would want to do anything with a player's mouse from a non-local script either; if you want to damage something (judging by the name of your script) then you should instead have the function send the amount of damage to deal to the object and then have the serverscript deal the damage, so it doesn't have to deal with the client's mouse.

Good luck with your game!

2 comments

0

the problem is im trying to use ray casting method for it and because of that i need mouse position

0

You can raycast on the localscript and then pass the necessary information from the raycast to the server

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