How would I script a teleport into dialogue?

Hello! I’m designing a dialogue system and I want the player to be moved to another location upon picking a certain choice. I know the teleport script, I just don’t know how I’d move the player there after they picked an option, and the only tutorial I could find was outdated and didn’t work. Thanks so much if you can help!

6 Likes

Hi there! The answer to this question really depends on what type of function you’re using for when the user actually has the option to pick where they want to go? This can be through a ClickDetector, TextButton, etc?

If this can be specified, I can help you from there.

2 Likes

It’s just a simple dialogue tree, the default roblox kind. I want it to work where you press an option, there’s a slight delay, and you move to a position.

3 Likes

So with Dialog boxes, it’s quite easy to function.

So we have the NPC with the Dialog in the head.
image

In this example, I only have two choices, but you can have as many as you’d like. I put the Dialogue script inside the dialog box.

The script would go as follows:

 script.Parent.DialogChoiceSelected:connect(function(player,choice)
 if choice.Name == "No" then
 		player.Character:MoveTo(PLACE YOU WANT TO GO)
 	elseif choice.Name == "Yes" then
 		player.Character:MoveTo(PLACE YOU WANT TO GO)
 	end
end)

Obviously, your choices would be completely different from mine, but I hope you understand!

1 Like

Great! And where would I put the script for dialouge that’s all the way at the end of a long tree?
(Like the photo here)dialoguetree
*I want the teleport to work when the endDialouge choice is pressed

2 Likes

You would want to place the script wherever the user will be exactly choosing where they wish to go

2 Likes

There was also an error whilst I was explaining the Dialog script to you, you’d want it to be a LocalScript, rather than a ServerScript. With the moving of the player, you’d most likely want an event to be fired to move the character.

3 Likes

Hey! So I used the script you gave me, but it didn’t work when I went to test it out. I put it inside the dialogue choice containing the choice I wanted to teleport the player, but nothing happened.

wait nvm i think i found the problem but I’ll have to test again lol

nope ok that didn’t fix anything it’s still not working

3 Likes

How odd, it had worked when I tried it myself. May I take a peek at the script you’re using?

2 Likes

Of course! Here’s the script:

	if choice.Name == "DialogueChoice" then
		wait (1000)
	elseif choice.Name == "endDialogue" then
		player.Character:MoveTo(-3401.3, -28.35, -991.5)
	end
end)
2 Likes

I see the issue! The problem is the :MoveTo function which I previously stated has to be performed via remote function.

Instead of the :MoveTo, You must fire a remote function and have a server script move the player’s character rather than the client.

4 Likes

Ohh, ok! Thank you! So I’d just use the localscript to fire off a remote event and use a regular script to teleport the player?

2 Likes

Yes you would! Let me know if that works out for you.

1 Like

Hey I’m so sorry to ask for help again but I can’t get it to work. I’ve tried tinkering around a bit with the code but nothing is working, would you be able to help?

(I tried to attach a copy of the place file but it wouldn’t let me, so I’ll send my scripts and explain where I’ve set everything)

So I have the localScript that fires the event inside the choice before the ending choice. I have the events in the replicatedStorage folder, and I have a regular script in a folder in the workspace. I used both the script I sent (but replaced the MoveTo with a fireEvent:server (set the event i wanted to use as a variable) and then on the regular script, I used this script: (I also switched between using MoveTo and the teleportation scripts provided on the developer hub)

local Event = game.ReplicatedStorage.Event1
function onEventFired()
	game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3(-3401.3, -28.35, -991.5))
end

Here’s the script I’m using on the LocalScript

script.Parent.DialogChoiceSelected:connect(function(player,choice)
	if choice.Name == "endDialogue" then
		game.ReplicatedStorage.Event1:FireServer()
	end
end)

Sorry for bothering you again, I just can’t seem to figure out the error

Hello,

Have you tried using

Instance:SetPrimaryPartCFrame(instance.CFrame)

To help this problem?

The way I’d input this is as follows (Server Script, aka the script that’s connecting the client to the server usually located in ServerScriptService that is firing the OnServerEvent event.

local Event = game.ReplicatedStorage.Event1
Event.OnServerEvent:Connect(function(player)
   player.Character:SetPrimaryPartCFrame(LOCATION.CFrame)
end)
1 Like

I am so dumb.
I made a spelling error naming the dialogue choice.
that’s why it’s not working
someone kill me now please why did i not
ugh

1 Like

yep no it’s still not working.
I have no idea what im doing wrong but whatever.
I will figure it out.
Eventually

You must use the localscript to fire the remoteEvent, and have the ServerScript as the listener.
As I see you’re using the LocalScript to listen for the event.

I’m not using a localscript, it’s just a regular one.

In the local script you might want to use the following code:

Event:FireServer(Player.Character)

In the server script:

Event.OnServerEvent:Connect(function(Player,Character)
       if Character:FindFirstChild("Humanoid) then
            Character:MoveTo(THE-INSTANCE-YOU-WANT-TO-MOVE-CHARACTER-TO)
       end
end)
1 Like