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

How do I make an NPC/AI Teleport a player somewhere? (UNANSWERED)

I've tried to teleport players with scripts, and I tried a GUI, but it doesn't correspond with the NPC. I need a way to make an npc teleport a player when they say a certain response. It has something to go with game.Workspace.NPC.Dialog.DialogChoice maybe? Idk I really need help it's for my game.

3 answers

Actually quite simple. (in my terms I guess. I've worked with this for a while now) So let's start with the function!

First we need to establish the directory to the dialog and add an argument. (player,choice) player being the player who clicked and choice being the dialog selected! Make sure that the directory is to the starting dialog and not its descendants!!!

game.Workspace.NPC.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)--Change the directory to the NPC you want and then to the Dialog (Right before DialogChoiceSelected)

Now we need to add the code.

	if choice.Name == "ChoiceA" then --change ChoiceA to the choice you want to be activated to execute the code!

Now for the code!

NPC = game.Workspace.NPC--Change this to the directory of the npc you want teleported!

NPC:MoveTo(player.Character.Torso.Position)--this method establishes the position of the model!

The Finished script!!

game.Workspace.NPC.Head.Dialog.DialogChoiceSelected:connect(function(player,choice)
	if choice.Name == "ChoiceA" then
NPC = game.Workspace.NPC

NPC:MoveTo(player.Character.Torso.Position)
	end
end)

I tested this myself so it should work! Hope this helped!!! Accept the answer if it did!!

3 comments

0

Can you dumb that down for me? xD

2

Can you learn a bit more lua and come back? xD

0

I just started scripting a few days ago. So, could you like, make the script out of my NPC and choices and such? I have 3 choices, I want choiceA to Teleport, and the NPC is named Krillin. If you could make the script with those, So I knew what you meant, then that would be a lot of help.

First off, may I remind you this isn't a request site, but moving on: You first have to use DialogueChoiceSelected, then check to see if the choice you wanted them to select was selected, then use CFrame.new to move the torso of the player somewhere.

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