"Character to mouse" teleportation not working?
Asked by
4 years ago Edited 4 years ago
I'm attempting to create a "character to mouse" teleportation system with a limit of 50 studs. However, when I run this LocalScript located in StarterCharacterScripts, it brings up no errors the output whatsoever, and nothing happens when I press F.
Here is the script:
01 | local uis = game:GetService( "UserInputService" ) |
02 | local player = game:GetService( "Players" ).LocalPlayer |
03 | local mouse = player:GetMouse() |
05 | local character = player.CharacterAdded:wait() |
06 | local torso = character:WaitForChild( "Torso" ) |
08 | local teleportRange = 50 |
10 | uis.InputBegan:Connect( function (inputObject, gameProcessed) |
12 | if inputObject.KeyCode = = Enum.KeyCode.F and not gameProcessed then |
14 | local position = mouse.Hit.p |
15 | local distance = position - torso.Position |
16 | local mag = distance.Magnitude |
18 | if mag < teleportRange then |
19 | torso.CFrame = mouse.Hit |
Any help or inquiries would be appreciated!