The code below should teleport the player from the hub-world, to a place inside of that game. However, I get the impression of that it fires before the player has clicked the button because of that it prints "ButtonClicked" before the player even gets a chance to press the button. Why does it work in the way it does?
local Player = game.Players.LocalPlayer local TeleportService = game:GetService("TeleportService") local function FirstOnClick() TeleportService:Teleport(Place1219Id,Player) print("ButtonClicked") end if TeleportationButtons.ScreenGui.First.MouseButton2Click then TeleportationButtons.ScreenGui.First.MouseButton2Click:Connect(FirstOnClick()) end
I've a first view of an if
statement not needed. Try to remove it and let only the line that calls the function.