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

How Do I get the player's mouse from a serverscript event?

local UIS = game:GetService("UserInputService")


UIS.InputBegan:connect(function(i, gameProcessedEvent)
	



if i.KeyCode == Enum.KeyCode.One then
	game.ReplicatedStorage.Test:FireServer()
	
end
	
	
	
end)

That is the local script^^^ Below is the server script









function ok(plr)
	
	
	
local  mouse = plr:GetMouse()

local b = Instance.new("Part")
b.Parent = game.Workspace
b.Position = mouse.Hit.Position





end





game.ReplicatedStorage.Test.OnServerEvent:Connect(ok)

Now this works perfectly fine in studio, but in a real server it says mouse is a nill object. Can someone explain please?

8 comments

0

The least you can do is write clean code and you couldn't even do that

0

I made it more simple, can you re read please.

0

The server can't see client sided non-replicated objects, so you have to send the position on the mouse from the client

0

Yeah but Im confused on how to do that, do I put it as an argument in the FireServer()?

0

First make a variable called "player" in the client script. Then make get the mouse with that variable. Make sure that the variable = the player in question.

0

Ok I did that, then I put it as a argument in FireServer, how do I access it in the serverscript?

0

Are you trying to find the mouse position?

0

I got it now I had to look up how to call it from the function

2 answers

I literally can't read your script. However, use InvokeServer() instead of FireServer if you are using a RemoteFunction.

1 comment

0

I made it more simple, can you re read it please.

Get rid of all the spaces

use

mouse.Hit.p

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