Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get a players mouse from a server script?

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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!

0
Is there a way I can create a local script from a server script? devisings 58 — 5y
0
You can but you can't write anything on it really. Instance.new("LocalScript") *unless if you are cloning from somewhere else* Igoralexeymarengobr 365 — 5y
Ad
Log in to vote
0
Answered by
EthanFins 104
5 years ago

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.

Answer this question