*Join Game* button in GUI?

I am making a GUI, where if you click a certain TextButton, it would teleport you to Welcome to Bloxburg.

I have tried this script below, as a LocalScript, as a child of the TextButton.

local TeleportService = game:GetService("TeleportService")
local placeID = 185655149

local function MouseButton1Click()
    local player = game:GetService("Players").LocalPlayer
    if player then
	    TeleportService:Teleport(placeID, player)
    end
end

When clicking it it doesn’t teleport to Bloxburg. What’s wrong with hthe script?

If you tried it in Roblox Studio it won’t work, it should work fine in-game tho since Teleport Service isn’t really a thing in Roblox Studio.

I published the game to Roblox, and then joined, and it still does nothing.

Oh yeah my bad you forgot to connect the function to the button, try this:

local TeleportService = game:GetService("TeleportService")
local Button = -- button location in the gui
local placeID = 185655149

local function MouseButton1Click()
    local player = game:GetService("Players").LocalPlayer
    if player then
	    TeleportService:Teleport(placeID, player)
    end
end

Button.MouseButton1Click:Connect(MouseButton1Click())

Oh yes. Thank you I will try that now.

local TeleportService = game:GetService("TeleportService")
local Button = -- button location in the gui
local placeID = 185655149

local function MouseButton1Click()
    local player = game:GetService("Players").LocalPlayer
    if player then
	    TeleportService:Teleport(placeID, player)
    end
end

Button.MouseButton1Click:Connect(MouseButton1Click) -- Fixed here.

Fixed your function, you called it for connection declaration:

Button.MouseButton1Click:Connect(MouseButton1Click())
1 Like

For some reason it isn’t working. Just double checking, the Button variable is script.Parent?

Is the script/localscript placed directly under the button?

theres no problem you forgot to turn on “allow third party teleport”
and yes the button variable is script.Parent

3 Likes