Problems with mouse position

I’m doing some testing with Mouse Position, the script i’m making is just supposed to get the mouse position and clone a part at it, these are my scripts so far:

LOCALSCRIPT

local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()

script.Parent.Activated:Connect(function()
	game:GetService('UserInputService').InputBegan:Connect(function(i,o)
		if o then return end
		if i.UserInputType == Enum.UserInputType.MouseButton1 then
			local MousePos = Mouse.Hit.p
			game.ReplicatedStorage.Events.Teleport:FireServer(Player, MousePos)
		end
	end)
end)

SERVERSCRIPT

game.ReplicatedStorage.Events.Teleport.OnServerEvent:Connect(function(Player, MousePos)
	local clone = game.ServerStorage.Part:Clone()
	clone.Parent = workspace
	clone.CFrame  = MousePos
end)

– I also tried .Position instead of CFrame.

Output:
ServerScriptService.Script:4: invalid argument #3 (CFrame expected, got Instance)

The player instance who fired the remote is already sent by default (you cannot change this) when using FireServer() or InvokeServer(), you’re actually passing 3 arguments to the OnServerEvent function: the player instance (sent by default), the player instance again (Player), and then the mouse position (MousePos).

So when you’re trying to index MousePos, you’re actually indexing the player instance. The solution would be to use this instead:

game.ReplicatedStorage.Events.Teleport:FireServer(MousePos)

Edit: another thing, you’re using CFrame.p which gives you the position, remove .p because you’re trying to set the CFrame

1 Like

Oh well. Live and learn!

Also i had to change it to .Position instead of .CFrame

But thanks!

1 Like