How would I use this in a server script?
local tool = script.Parent
local rs = game.ReplicatedStorage
if mouse.Target and mouse.Target.Parent then
if(mouse.Target.Name == "Grass") then
local Mpos = mouse.Hit.Position
local NewHole = rs.BrownHole:Clone()
newHole.PrimaryPart.Position = Mpos
newHole.Parent = workspace
If you want the change to be visible on the server, you need to make a remote event to inform the server of the changes.
You can fire a remote function to grab the player’s mouse. Obviously, you could check what’s returned for security reasons.
I know I need to use a remote event, I just don’t know how to transfer mouse position, which is what I guess I should be asking.
Pass it as an argument in the remote event.
local mouse = RemoteFunction:InvokeClient()
-- security checks
RemoteFunction.OnClientInvoke = function()
You cannot pass objects as arguments, and even if you did this would still not work as the players mouse does not replicate to the server. All your code here would do is return nil.
You’re right for the second part since Mouse isn’t replicated to the server, but you can pass objects as arguments… sorry for the misleading information. Another alternative is only to pass other values I guess, such as the mouse position.
I’d like to say it’s also probably never a good idea to use InvokeClient.
For something like this, a RemoteEvent’s FireServer would do just fine.
In response to OP, you would simply pass the property you want from the mouse as an argument when calling FireServer.
In this case you would put something along the lines of
remoteEvent:FireServer(mouse.Hit.Position) in your Button1Down event and have the server handle the rest.
return game:GetService("Players").LocalPlayer.Mouse.X, game:GetService("Players").LocalPlayer.Mouse.Y