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:
local uis = game:GetService("UserInputService") local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local character = player.CharacterAdded:wait() local torso = character:WaitForChild("Torso") local teleportRange = 50 uis.InputBegan:Connect(function(inputObject, gameProcessed) if inputObject.KeyCode == Enum.KeyCode.F and not gameProcessed then local position = mouse.Hit.p local distance = position - torso.Position local mag = distance.Magnitude if mag < teleportRange then torso.CFrame = mouse.Hit else print("Too far") end end end)
Any help or inquiries would be appreciated!
Maybe try on line 20: torso.CFrame = CFrame.new(mouse.Hit.p)
. It won't keep the players rotation but that can be easily fixed. If you need anymore help or this answer didn't work just say so! I will help to the best of my abilities.