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

bad argument #1 (Vector3 expected, got number)? I have no idea.

Basicly this error: bad argument #1 (Vector3 expected, got number) Im kind of in a rush rn, And can you please explain it and not just post the answer?


script.Parent.Touched:Connect(function(P) -- On part touched connect function with the argument P
	--    local PL = game.Players:GetPlayerFromCharacter(P.Parent) -- Gets player
	--    local PT = PL.Character:FindFirstChild("HumanoidRootPart") -- Gets the torso
	--
	--    if PL then -- If the player has been found then
	--    if PT then -- If the player's torso has been found then
	--        PT.CFrame = PT.CFrame + Vector3.new(0,N,0) -- Teleports the player 10 studs up
	--    else -- If there isn't a torso then
	--        warn("Torso was not found") -- Warn that torso wasn't found in the console
	--    end
	--    else -- If the player wasn't found then
	--        warn("Player was not found") -- Warn that the player wasn't found in the console
	--    end
	    local H = P.Parent:FindFirstChild("Humanoid")
	    if H then
		    print("Found")
			P.Parent.HumanoidRootPart.Position = script.Parent.Parent.Parent.Elevator2.Walls.Floor.Position.Y + Vector3.new(0,6,0)
			wait()
		end
end)
-- Ignore the green parts :|

2 answers

✓ Accepted answer

The answer is pretty self explanatory. You tried to add an integer to a Vector3. To make it more clear to you, this is what the game sees: Number + Vector3. The game becomes confused because it doesn't know in which axis the number should go to.

To fix this, you would have to convert the number into a Vector3 object and If I am correct, you want that number to represent the y axis.

local yAxis = Vector3.new(0,script.Parent.Parent.Parent.Elevator2.Walls.Floor.Position.Y,0)

P.Parent.HumanoidRootPart.Position = yAxis + Vector3.new(0,6,0)

1 comment

0

Oh ok. Very weird, But ok.

It's much more better to use CFrame; sorry that I couldn't explain much like you asked.

script.Parent.Touched:Connect(function(P)
	local H = P.Parent:FindFirstChild("Humanoid")
	if H then
		print("Found Humanoid")
		P.Parent.HumanoidRootPart.CFrame = script.Parent.Parent.Parent.Elevator2.Walls.Floor.CFrame + Vector3.new(0, 6, 0)
		wait()
	end
end)

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