I want to make a tool that spawns a model at the player's mouse, here is my code if you want it
Localscript
local player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local Mesa = RS.Towers.Mesa
local Mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
script.Parent.SpawnTower:FireServer(Mouse)
end)
ServerScript
local RS = game:GetService("ReplicatedStorage")
local Mesa = RS.Towers.Mesa
script.Parent.SpawnTower.OnServerEvent:Connect(function(Mouse)
local newtower = Mesa:Clone()
newtower.Parent = game.Workspace
newtower:MoveTo(Mouse.Position)
newtower.Name = "Mesa Tower"
end)
Instead of spawning at the player's mouse, it just spawns the model where it originally was. How fix?
Fix: localscript
local player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local Mesa = RS.Towers.Mesa
local Mouse = player:GetMouse()
script.Parent.Activated:Connect(function()
local Mousepos = Mouse.Hit.p --I need to get the mouse position right before firing the event
script.Parent.SpawnTower:FireServer(Mousepos) --Send the mouse pos to the server
end)
ServerScript
local RS = game:GetService("ReplicatedStorage")
local Mesa = RS.Towers.Mesa
local tool = script.Parent
local player = tool.Parent.Parent
script.Parent.SpawnTower.OnServerEvent:Connect(function(player, Mouse) -- Player is the first arguement always when firing from local
local newtower = Mesa:Clone()
newtower.Parent = game.Workspace
newtower:MoveTo(Mouse) --We already have the mouse pos so move to mouse
newtower.Name = "Mesa Tower"
end)

2 comments
Mouse.Hit represents the CFrame, in 3D space, of where the mouse clicked on the player's screen. You can't pass Hit itself to the server, but you can pass Hit wrapped in a CFrame.new() constructor to the server. It sounds weird and is weird, but it works.
You cannot construct a CFrame from a CFrame; you are able to pass Mouse.Hit through a Remote.