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

Why doesnt this function fire when it shouldn't?

Asked by 5 years ago

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

Log in to vote
1
Answered by
Time_URSS 146
5 years ago

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

Ad

Answer this question