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!

3 comments
im looking into it
Why did you put that "not" in the if statement [not gameProcessedEvent]
so that it doesn't detect input if the player is chatting