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

How can I fix this teleport script that is activated by the clicking of a button on a gui?

Asked by
jtp40 7
8 years ago

I've tried multiple things, but this is the closest I think I have gotten. Before this is the code for an image button that when pressed, makes some text guis and in 69.72 seconds it teleports to the place I want. I don't know what I'm doing wrong. (The image button and the text gui's all work)

wait(69.72)
    local TeleportService = game:GetService("TeleportService")

    local memeplace = 421113879 --Why did I name it memeplace...

    game.Players.PlayerAdded:connect(function(player)
        TeleportService:Teleport(memeplace, player)
    end)

Edit 1: To be more specific, I just want it to teleport to 421113879. When I test it, there is no error message, I tried this new code, the same thing happened. I'll show the whole context of code. It's a local script inside an image button inside a screen gui inside the starter gui folder. The only thing that isn't working is the teleport function. Another fact to add is that there are no errors in the output and script are analysis.

local button = script.Parent
local sound = button:WaitForChild('Sound')
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local function onButtonClick()
    sound:Play()
    local screen = Instance.new("ScreenGui")
    screen.Parent = PlayerGui
    local textLabel = Instance.new("TextLabel")
    textLabel.Parent = screen
--The text is here. It's very long, I'll skip that part. (around 10 lines when put into google docs)
textLabel.Size = UDim2.new(0.5,0,0.5,0)
    textLabel.FontSize = Enum.FontSize.Size8
    textLabel.TextScaled = true
    local textLabel = Instance.new("TextLabel")
    textLabel.Parent = screen
--More text :l
textLabel.Position = UDim2.new(0,0,0.5,0)
    textLabel.Size = UDim2.new(0.5,0,0.5,0)
    textLabel.TextScaled = true
    local textLabel = Instance.new("TextLabel")
    textLabel.Parent = screen
    textLabel.Position = UDim2.new(0.5,0,0,0)
    textLabel.Size = UDim2.new(0.5,0,0.5,0)
    textLabel.TextScaled = true
--So much text
wait(69.72)
    local function PlayerAdded()

    local TeleportService = game:GetService("TeleportService")
    local memeplace = 421113879
    game.Players.PlayerAdded:connect(function(player) --Why did I name it memeplace...
        TeleportService:Teleport(memeplace, player)
    end)
    end
    end
button.MouseButton1Click:connect(onButtonClick)

Edit 2: Sorry wfvj014. I didn't understand what you were saying until now. I'll try the new idea you put.

game.Players.PlayerAdded:connect(function(player) --Why did I name it memeplace...
        TeleportService:Teleport(421113879, player)
        local TeleportService = game:GetService("TeleportService")
    end)
    end

It still doesn't work, there is no error message when this part runs but there is a warning saying "Unknown global 'TeleportService'" When I look at the script. I would like to know a cleaner way to do this.

0
I'm not 100% on what you're trying to do, but try moving all the code from line 1-5 inside of the PlayerAdded function. User#11440 120 — 8y
0
It seems you're using the player added event here which to me doesn't make sense and is prob your problem. Can you show the full context of the code? EgoMoose 802 — 8y
0
Did you try what I suggested? If so, what happened? User#11440 120 — 8y
0
Still didn't work. Doesn't my second piece of code have what you suggested? jtp40 7 — 8y
View all comments (2 more)
0
No, it does not. On line 28, what are you even trying to do? Also, are there any errors? User#11440 120 — 8y
0
Nothing tells me I am having an error jtp40 7 — 8y

Answer this question