Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I fix (Vector3 expected, got Object)?

I'm having this error -- > Workspace.Mdoor.Union.Script:26: bad argument #2 to '?' (Vector3 expected, got Object)

Script was working fine but I had to revert versions because I accidentally lost the script and I can't remember how I fixed this error. Can anyone help?

local rs = game:GetService("ReplicatedStorage")
local r = rs.Remotes:WaitForChild("DoorOpen1")

r.OnServerEvent:connect(function(HRP)
	if (script.Parent.Position - HRP).magnitude <= 3 then --Error Happens Here!
		print(r.Name.. " was fired!")
		local door = game.Workspace.Mdoor:WaitForChild("Union")
		local hinge = game.Workspace.Mdoor:WaitForChild("Hinge")
	
		local hingep = hinge.Position

		for i = 1, 120 do
			door.CFrame = CFrame.new(hingep)* CFrame.Angles(0,math.rad(i),0) * CFrame.new(0.294,0,2.89500)
			wait()

		end
	end
end)

Also I should note HRP is defined as LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position

2 answers

✓ Accepted answer

RemoteEvents

See, HRP isn't actually defined as that at all. The signature for OnServerEvent is (player, ...) rather than the (...) you're expecting, with the first arg being the player who actually fired the event.

The simple fix to this is to change the connection signature to (player, HRP)

or to make it easier to understand, other guy is fully correct but here is a code to what he means

local rs = game:GetService("ReplicatedStorage")
local r = rs.Remotes:WaitForChild("DoorOpen1")

r.OnServerEvent:connect(function(player,HRP)
    if (script.Parent.Position - HRP).magnitude <= 3 then --Error Happens Here!
        print(r.Name.. " was fired!")
        local door = game.Workspace.Mdoor:WaitForChild("Union")
        local hinge = game.Workspace.Mdoor:WaitForChild("Hinge")

        local hingep = hinge.Position

        for i = 1, 120 do
            door.CFrame = CFrame.new(hingep)* CFrame.Angles(0,math.rad(i),0) * CFrame.new(0.294,0,2.89500)
            wait()

        end
    end
end)

1 comment

0

but as a pretty decent scripter i dont find these things hard

This discussion is preserved as it was. New answers, comments, and votes are closed.