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

Can anyone help with place teleportation?

Asked by
Aeike 9
8 years ago
Edited 8 years ago

I'm having trouble with place teleportation. Just to summarize what my problem exactly is; I'll start with the general area everything is in. I'm trying to get it so that when you press a TextButton on your screen, it will teleport you to a different server. And I've put a ScreenGUI in the StarterGUI folder, and inside that is a TextButton. I've tried multiple scripts I know; but it hasn't worked; for instance, getting TeleportService and doing something else. I forgot exactly what I did to be completely honest; but I hope that doesn't get in the way of anything. Any help?

Script: script.Parent.NewCharbutton.MouseButton1Click:connect(function() game:GetService('TeleportService'):Teleport(game.Players.LocalPlayer, [517540166]))

Gyazo of my folders: https://gyazo.com/e29b417fb46b64e965c3e380dd9b6407

Gyazos of the code itself: https://gyazo.com/ff71655143ab294f33872f4c431d33c8 https://gyazo.com/95a9fda8aba328e9eb8a8aed18f0226d

0
Can you give us an example of a script? TheDeadlyPanther 2460 — 8y
0
Uhh, can you post your current script? If this is a request, it should not be on here. FrostTaco 90 — 8y
0
@Above I'll provide a script! Let me quickly edit. Aeike 9 — 8y
0
Put it in a code block. Is the script a LocalScript? It needs to be a LocalScript to use LocalPlayer. TheDeadlyPanther 2460 — 8y
0
It is a localscript; just provided both the script and a gyazo of the folders I put it in. Aeike 9 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

Here's the fixed code, with explanations:

local id = 517540166 -- simplifying, easier to change things without delving into the code

local tp = game:service("TeleportService") -- optimization, so the script doesn't have index this more than one time
local button = script.Parent:WaitForChild("NewCharbutton") -- optimization
local p = game.Players.LocalPlayer -- optimization

button.MouseButton1Click:connect(function()
    tp:Teleport(p, id)
end) -- there was no end), which is needed

The gyazo link does not actually work, for whatever reason, it may just be my PC, as the image just doesn't seem to appear (the actual image element doesn't seem to exist).

You should learn to format your questions properly, especially links and code blocks (check out the icons on top of the box questions/answers are in).


Hope I helped!

~TDP

0
I understand the script - and I do appreciate the time you took into helping me! However, when I actually run the game itself, and hit my TextButton, it doesn't teleport me to the place. I hope you can help me with this; if you don't mind. Aeike 9 — 8y
0
@TheDeadlyPanther Nevermind; everything is well. Thank you! Aeike 9 — 8y
0
np lol TheDeadlyPanther 2460 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Simple fix, you forgot to add

end)

Answer this question