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

How the heck do I teleport an NPC in the Workspace somewhere?

Asked by 5 years ago

Im only a beginner at scripting and I have no idea how teleporting something that contains a Humanoid works.

I tried moving the torso, the humanoid, using moveto? (i dug around in some free models to try to salvage that) and i cant seem to do it.

Im just very lost, and I feel like the answer is simple. Anywhere anyone can point me?

1
You're all good to go! Ziffixture 6913 — 5y

2 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Using the Humanoid for :MoveTo(), I wouldn't use as it causes it to walk instead of actually teleport. Instead, target the Model. As it will provide the PrimaryPart, which should be the Instance passed to teleporting

So to solve your issue, this is what your Script should look like

local CoordianteFrame = workspace:WaitForChild("Location1").CFrame
local UserInputService = game:GetService("UserInputService") --// Random Event fire.
local Char = workspace:WaitForChild("NPC")
UserInputService.InputBegan:Connect(function(InputObject, GameProcessed)
    pcall(function()
        if (InputObject.KeyCode == Enum.KeyCode.E and not GameProcessed) then
            if (Char:FindFirstChild("Humanoid"):IsA("Humanoid")) then --// Same principles
                Char:MoveTo(CoordianteFrame.Position)
                return
            end
            print(Char.Name.." doesn't have a Humanoid.")
        end
    end)
end)

Hope this sends you in the right direction, I suggest reading about :MoveTo() to get a better grasp, also UserInputService may be new to you, so check out UserInputSerivce when you can. Good Luck! lots have changed in this past year.

0
I apologize, I feel very inept for not specifying - im attempting to move an NPC located in the workspace to a given coordinate, not a or the player. But thank you, this script is helpful for another problem I have had - I havent scripted on ROBLOX in a while in general. Not up to speed. Octocentillion 15 — 5y
0
If you have a location defined by a Part, I can easily configure this answer to accommodate to your requirements Ziffixture 6913 — 5y
0
Char is what I named the Variable for the NPC, sorry if that was confusing:) Ziffixture 6913 — 5y
0
Yeah, my intention is to periodically move said NPC to certain parts (i.e. location1,2, etc) when events happen, like a click detection or a part being touched. Nothing too crazy, just simply moving the NPC around Octocentillion 15 — 5y
View all comments (16 more)
0
Is the desired location a physical object? If so please provide the reference path Ziffixture 6913 — 5y
0
Yes, its a part in the workspace. game.Workspace.location1 would be the path. Octocentillion 15 — 5y
0
Alright, I'll get to work Ziffixture 6913 — 5y
0
Take your time. I appreciate the help Octocentillion 15 — 5y
0
That should do it for you? Ziffixture 6913 — 5y
0
The output keeps telling me that = is expected where + is on line 10. Have I not used the correct type of script, put it in the right place, or is it just an error? Octocentillion 15 — 5y
0
(line 07 on what you posted) Octocentillion 15 — 5y
0
Try switching the Variable Name, it could get confused? Ziffixture 6913 — 5y
0
Doesnt seem to be working. maybe we could talk on discord to sort this out with more ease, if youre alright with that? Octocentillion 15 — 5y
0
Oh I wrote Chat instead of Char Ziffixture 6913 — 5y
0
my device is about to die, I can handle this in about an hour f that’s okay? Ziffixture 6913 — 5y
0
Tomorrow might work better, its getting late where I live. Ill message you on ROBLOX with the rest of the situation, id prefer to handle it from whatever can be established from that. Octocentillion 15 — 5y
0
again, thanks for everything. greatly appreciated! Octocentillion 15 — 5y
0
No problem! Ziffixture 6913 — 5y
0
Nice syntax error on line 7 User#24403 69 — 5y
0
That should fix everything, up a bit late last night Ziffixture 6913 — 5y
Ad
Log in to vote
1
Answered by
asadefa 55
5 years ago

To teleport something with a humanoid, you need to change the CFrame value.

workspace.NPC.PrimaryPart.CFrame = CFrame.new(x, y, z)

x, y, and z are the coordinates of the destination.

Hope this helps

0
Thank you. This helps me a lot. Octocentillion 15 — 5y
0
I also was searching for an answer like this.Thank you tho. MR4MYSTERY_WORKER 15 — 4y

Answer this question