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

Mouse.Hit.Position giving an error (I'm trying to use a server script)?

Using this line of code, I just took a snippet out of my script, it gives me the error "attempt to index nil with 'Hit'". I have no idea what this means, can I not use a that code in a server script?

game.ReplicatedStorage.Events.ShootEvent.OnServerEvent:Connect(function(player)
	
	local mouse = player:GetMouse()
	local ray = Ray.new(hole.CFrame.p, (mouse.Hit.Position - hole.CFrame.p) * range.Value)
end)

2 answers

✓ Accepted answer

I would get the position on the client then fire it to the server. I don't think you can get the mouse on the server.

6 comments

0

How would I send the position of the mouse to a server script though?

0

through the arguments

0

when using :FireServer, fire the position of the hit

0

So, like this? game.ReplicatedStorage.Events.ShootEvent:FireServer(ray)

0

precisely

0

It works, thanks.

The PlayerMouse Instance can only be used in LocalScripts. Consider adding a parameter to the RemoteEvent that passes the players mouse.Hit.Position

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