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

"Character to mouse" teleportation not working?

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

1

im looking into it

0

Why did you put that "not" in the if statement [not gameProcessedEvent]

0

so that it doesn't detect input if the player is chatting

1 answer

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.

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