TextButton.Activated not working

Interesting, it should be able to work with only 1 mouse click. Can you try again?

EDIT: I tested this exact same thing within Studio and I was able to teleport with only 1 click. Do you have any other scripts that are using the same button?

1 Like

Tried again, I had to click 6 times before it teleported me.

1 Like

That’s extremely odd. Try resetting Studio and trying again. If it still behaves like that, you could try making a bug report.

1 Like

Yes, a script that makes the ScreenGui enabled when players stand on a specific part, and another script that makes the ScreenGui disables when they click on the TextButton

1 Like

I think it is behaving like that because you’re using multiple scripts for 1 button, but I’m not sure. Try making a separate button for teleporting, and see if you still need to do 5/6 clicks. Let me know how it goes.

2 Likes

Tried it with a separate button, and it works perfectly! Thanks for your help!

However, I do find it quite inconvenient that I need to make two separate buttons to close the GUI and teleport the player.

1 Like

That isn’t the solution, his text button isn’t even working at the first place and he is doing it the right way when talking about setting the CFrame.

1 Like

Among testing, turns out it’s a LOT better to use the .Visible property for each TextLabel, TextButton or whatever than using .Enabled for ScreenGui’s. When I used .Enabled (even though it was quicker), I had to click multiple times before it actually worked, however by modifying each TextLabel, TextButton (even though it’s slower) .Visible property, it makes the whole script smoother and lets me make the GUI not visible while also teleporting the player!

Here’s the script:

print("This is inside PlayerGui")
local player = game.Players.LocalPlayer
local tphere = game.Workspace.level1.tptohere.TPPos

--buttons--
local tpbutton = script.Parent


tpbutton.MouseButton1Click:Connect(function()
	player.Character.HumanoidRootPart.CFrame = tphere.CFrame
	player.PlayerGui.ScreenGui.TextButton2.Visible = false
	player.PlayerGui.ScreenGui.TextLabel.Visible = false
	print("TP worked")
end)

So, I guess instead of modifying a ScreenGui’s enabled property, modify each Label or Button’s Visible property as it’s a lot more convenient.

3 Likes

That’s great to hear! If your problem is solved, make sure to mark the solution so people who are having the same issues can view this topic.

1 Like

Setting the character’s CFrame with a Vector3 will result in an error (CFrame expected, got Vector3). It should be better if you use the correct datatype.

1 Like

To simplify matters and to not have to wait for the TextButton to replicate before setting up a listener, just put the LocalScript directly under the button:

local button = script.Parent

local function onClicked()
    print "clicked"
    -- code
end

button.Activated:Connect(onClicked)
1 Like

and if i need to apply the same handler for many buttons - then what? copypaste the script?

bro really responded 4 yearss later