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

"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:

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!

1
im looking into it Clorize 31 — 4y
0
Why did you put that "not" in the if statement [not gameProcessedEvent] Clorize 31 — 4y
0
so that it doesn't detect input if the player is chatting DemonHunterz6 35 — 4y

1 answer

Log in to vote
0
Answered by
ImTrev 344 Moderation Voter
4 years ago

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.

Ad

Answer this question