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

Can't Teleport a player?

Asked by 6 years ago

I'm trying to teleport a player ~50 studs in front of where the camera is looking at, whenever they double tap the "w" key. I know how to teleport the player and find the direction of the camera (At least I think I'm doing it right, I could be wrong), but I can't seem to put them together without getting the same error:

15:33:11.773 - Players.McQuakyDuck.PlayerGui.LocalScript:37: bad argument #2 to '?' (Vector3 expected, got number)

All the code is in a LocalScript inside of StarterGui

01--Getting the Camera
02game.Players.PlayerAdded:connect(function(player)
03    script.LocalScript:clone().Parent = player.CharacterAdded:wait()
04end)  
05 
06 
07--Local Variables 
08local cam = workspace.CurrentCamera
09local player = game.Players.LocalPlayer
10game.Workspace:WaitForChild(player.Name)
11local Char = player.Character
12local Humanoid = Char:WaitForChild("Humanoid")
13local Mouse = player:GetMouse()
14local lastTapTime = 0
15local clicked = false
View all 60 lines...

Any help is appreciated!

0
Check out my edited answer to the previous question User#21908 42 — 6y

1 answer

Log in to vote
2
Answered by
LeadRDRK 437 Moderation Voter
6 years ago

You are trying to add a number to a lookVector, which is a Vector3, and they can’t be added together. You can only add a Vector3 to a Vector3 or a Vector3 to a CFrame. So, to correctly do this, you need to add the lookVector to another Vector3, not a number. And because lookVector is already a Vector3, you do not need to use Vector3.new(). Here’s how it’s correctly done:

I’d assume you want to add 50 studs on each axis:

01--Getting the Camera
02game.Players.PlayerAdded:connect(function(player)
03    script.LocalScript:clone().Parent = player.CharacterAdded:wait()
04end)  
05 
06 
07--Local Variables 
08local cam = workspace.CurrentCamera
09local player = game.Players.LocalPlayer
10game.Workspace:WaitForChild(player.Name)
11local Char = player.Character
12local Humanoid = Char:WaitForChild("Humanoid")
13local Mouse = player:GetMouse()
14local lastTapTime = 0
15local clicked = false
View all 60 lines...
Ad

Answer this question