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?
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())
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: