Is there a way to send mouse target to sever?
RemoteFunctions
--Server script in serverscriptservice local rf = game.ReplicatedStorage.RemoteFunction -- If you want to invoke the RemoteFunction, use the `:Invoke` method. You must also include a player as the first argument -- Example: -- rf:InvokeClient(game.Players.Doobb_yyus) --Client script in StarterPack, StarterCharacterScripts, or StarterPlayerScripts local rf = game.ReplicatedStorage.RemoteFunction function rf.OnClientInvoke() return Mouse.Target end
Note: if the parent wasn't created on the server, it'll be nil on the server
You need to use Local Script
and Remote Event
Roblox Wiki Page - Local Script
Roblox Wiki Page - RemoteEvent
Roblox Wiki Page - Mouse.Target
Roblox Wiki Page - Mouse.Button1Down
You can see Roblox Wiki for more information.
First insert a RemoteEvent on ReplicatedStorage, insert a Script
on ServerScriptService and put this code:
local event = game:GetService("ReplicatedStorage").RemoteEvent -- Location of event! event.OnServerEvent:Connect(function(p,hit_target) if hit_target ~= nil then warn(tostring(hit_target)) else warn("The mouse target is nil!") end end)
Now insert a LocalScript on StarterGui and put his code:
repeat wait() until game.Players.LocalPlayer local plr = game.Players.LocalPlayer local Mouse = plr:GetMouse() local event = game:GetService("ReplicatedStorage").RemoteEvent -- Location of event. Mouse.Button1Down:Connect(function() event:FireServer(Mouse.Target) end)
If you want to get position you can use this:
Script
on ServerScriptService:
local event = game:GetService("ReplicatedStorage").RemoteEvent -- Location of event event.OnServerEvent:Connect(function(p,hit_pos,hit_target) if hit_target ~= nil and hit_pos ~= nil then warn("Name: " .. tostring(hit_target) .. "\nPosition: " .. tostring(hit_pos)) else warn("The mouse target is nil!") end end)
LocalScript
on StarterGui:
repeat wait() until game.Players.LocalPlayer local plr = game.Players.LocalPlayer local Mouse = plr:GetMouse() local event = game:GetService("ReplicatedStorage").RemoteEvent -- Location of event Mouse.Button1Down:Connect(function() event:FireServer(Mouse.Hit.p,Mouse.Target) end)
Hope it helped! :)