Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Bad argument #3 to 'Position' (expected Vector3, got object) how do I fix it?

Asked by
2ndwann 131
5 years ago
Edited 5 years ago

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)

2 answers

Log in to vote
1
Answered by 5 years ago

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

Ad
Log in to vote
1
Answered by 5 years ago

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)

0
so now the coords variable is actually the coordinates Questofmagicfarts 55 — 5y
0
so now the coords variable is actually the coordinates Questofmagicfarts 55 — 5y
0
Thank you very much, im going to try it! 2ndwann 131 — 5y

Answer this question