How would I do this?
--LocalScript- --Gets Mouse --Sends Mouse Position --ServerScript- --Recieves Mouse Position --Uses it for blah blah blah.
This is what I tried but It didnt work.
-LocalScript- Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction') local Player = game.Players.LocalPlayer mouse = Player:GetMouse() MousePosition = mouse.Hit.p Remote:InvokeServer(MousePosition) -ServerScript- Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction') Remote.OnServerInvoke = function(player, MousePosition) a = Instance.new('Part') a.Position = MousePosition end
local mouse = game.Players.LocalPlayer:GetMouse() for ex: local part = Instance.new("Part", workspace) -- makes a part in the workspace part.Position = mouse.Hit.p --spawns a part where the player's mouse is
Please answer my question if it worked, or comment if any error's.
This is in the ServerScript, you can just Fire the Server in the localscript, and make the ServerScript do what you need.
For this, you don't want to use a remotefunction
and it will yield your localscript until the server returns a value, something you don't need in this case. Instead use a remoteevent
, which only sends data 1 way.
localscript:
Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction') local Player = game.Players.LocalPlayer mouse = Player:GetMouse() MousePosition = mouse.Hit.p Remote:FireServer(MousePosition)
Server:
Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction') Remote.OnServerEvent:Connect(function(player,position) a = Instance.new('Part') a.Position = MousePosition a.Parent=workspace end)
Also you forgot to parent the part to the workspace, otherwise it will have a parent of "nil" and never show.
Hope this helped! If it did, please accept the answer