I have a LocalScript in a tool; heres the code
player = game.Players.LocalPlayer mouse = player:GetMouse() script.Parent.Activated:Connect(function() game.ReplicatedStorage.BallistaFired:FireServer(player, mouse) print(player) print(mouse) end)
and heres a script inside the same tool that responds to the FireServer
game.ReplicatedStorage.BallistaFired.OnServerEvent:Connect(function(player, mouse) wait(.25) print(player) print(mouse) end)
Even though each script is told to print the same variables, they come out with different outputs. The LocalScript prints "Instance" for the "print(mouse)" while the script prints "ewdoggypoopoo"(my username) for the output. Why is this? And how could I get a Players Mouse to a server script?
You don't need to send player, this is automatically detected by the server. By sending player as an argument you're sending it twice. All you need is:
game.ReplicatedStorage.BallistaFired:FireServer(mouse) game.ReplicatedStorage.BallistaFired.OnServerEvent:Connect(function(player, mouse)
And as the other answer mentioned the mouse will be nil on the server.
This is a very common problem and I recommend you try searching for an answer before having to ask here.
The Mouse object is absent on the server, so it (the server) cannot index or receive the instance. To access the values from the mouse, you must use RemoteEvents and/or RemoteFunctions and pass the required values while using the remote.
You are trying to send a reference to a local object, but since the object doesn't exist on the server, the server receives nil.
The correct method is to send whatever information the server needs from the mouse from the client
Example:
-- LocalScript local player = game.Players.LocalPlayer local mouse = player:GetMouse() local remote = game.ReplicatedStorage.MyRemote remote:FireServer(mouse.Target) -- ServerScript local remote = game.ReplicatedStorage.MyRemote remote.OnServerEvent:Connect(function(player, target) print(player.Name.."'s mouse is pointing at".. target or "the sky") end)