I want to change the position of the part based on the CFrame of the mouse, but I get this error: Bad argument #3 to 'Position' (expected Vector3, got object) I am using a RemoteEvent to transfer the CFrame value from the client to the server.
Here is the LocalScript:
local replicatedstorage = game:GetService("ReplicatedStorage") local Player = game.Players.LocalPlayer -- Also, I noticed you weren't using 'local' to define your variables. Use that, as it sets the variable apart from a global variable. local Mouse = Player:GetMouse() local MouseCFrame = Mouse.Hit local MousePosition = MouseCFrame.p local event = replicatedstorage:WaitForChild("TestEvent") function printpos() MouseCFrame = Mouse.Hit MousePosition = MouseCFrame.p event:FireServer(MousePosition) print (MousePosition) end Mouse.Button1Down:Connect(printpos)
Here is the Script for the server:
local replicatedstorage = game.ReplicatedStorage local event = Instance.new("RemoteEvent") event.Name = "TestEvent" event.Parent = replicatedstorage local part = game.Workspace.test function movePart(coords) part.Position = coords print(coords) end event.OnServerEvent:Connect(movePart)
First of all this
function printpos() MouseCFrame = Mouse.Hit MousePosition = MouseCFrame.p event:FireServer(MousePosition) print (MousePosition) end
was unnecessary all you needed to do was this
function printpos() event:FireServer(Mouse.Hit.p) print(Mouse.Hit.p) end
Try that other than that i dont know why its tripping
it doesn't work because in the script (not the localscript) the coords variable is actually the player who fired the remote event so do this
local replicatedstorage = game.ReplicatedStorage local event = Instance.new("RemoteEvent") event.Name = "TestEvent" event.Parent = replicatedstorage local part = game.Workspace.test function movePart(plr,coords) print(coords) part.Position = coords end event.OnServerEvent:Connect(movePart)