Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesnt this function fire when it shouldn't?

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

1 answer

✓ Accepted answer

I've a first view of an if statement not needed. Try to remove it and let only the line that calls the function.

This discussion is preserved as it was. New answers, comments, and votes are closed.