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 a players mouse from a server script?

I am trying to make a script for a script builder game.

(If you don't know what that is, you just upload a script to the game and it runs it and you can fight people etc with your scripts.)

I am just confused about how people get the players mouse in the game from a server script? I've seen people do it with guns and such.

Anyone know how to or any ideas?

2 answers

You can't Server scripts are made for server side stuff only. A way you can use to obtain the player's mouse position for example is using Remote Events!

EXAMPLE: Local script:

mouse = game:GetService("Players").LocalPlayer:GetMouse()
remote = workspace.Remote -- remote location
wait(10) -- wait 10 secs :)
remote:FireServer(mouse.Hit.p)

Server script:

workspace.Remote.OnServerEvent:Connect(function(player,HitPos)
	print(HitPos) -- print mouse position in 3d space
	print(player.Name) -- print player who fired it :D
end)

Remember that the local script should be in Clientside environment such as PlayerGui or PlayerScripts for example

Good luck!

2 comments

0

Is there a way I can create a local script from a server script?

0

You can but you can't write anything on it really. Instance.new("LocalScript") unless if you are cloning from somewhere else

This is correct you cannot get a mouse using a server script just like when you can't get the current camera in a server script they're only things that can be access in a local script.

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