Text button stops working

Hi,

I have a problem with a TextButton and accessing it. For some reason, my text button stops working after I move it onto a new location such as under a folder or a frame.

It works fine in its first location but after the TextButton is moved somewhere else with a script it stops working.

I had this problem yesterday but I thought I had fixed it, but no luck.
Can someone help out?

Thanks in advance,

2 Likes

Try making sure that your script is looking in the right spot for the TextButton. Since you moved the TextButton around, make sure you’ve updated the script so that it looks in the new Frame or Folder, instead of the old spot.

The script is looking in the right spot, but when I click on the button it doesn’t do anything.

Hmm, could you send the script?

make sure script is not disabled

The script is not disabled. characters

if it not clickable change the z index
it should be higher or same as the parent or background

So basically,

I’m making a script that creates a text button for the number of players in the game. (ex. 2 players = 2 buttons)

When a player joins the game the script creates all the buttons accordingly. When a player leaves the game it moves the TextButton to a folder “Unused” and the TextButton is made invisible.

When a player joins the game it takes the TextButton from the “Unused” Folder and puts it back in the folder “In-Use” where other buttons are visible. But when its placed back the button stops working.

Removing script:

    local playerButton = playerFolder:FindFirstChild(playerRemoved.Name)
	playerButton.Name = "Unused"
	playerButton.Text = ""
	playerButton.Visible = false
	playerButton.Parent = unusedFolder

Adding back script:

            local newTemplate = unusedFolder:FindFirstChild("Unused")
			newTemplate.Parent = playerFolder
			newTemplate.Name = playerJoined.Name
			newTemplate.Text = playerJoined.Name
			newTemplate.Visible = true
			newTemplate.BackroundTransparency = 0
			

1 Like

It is clickable, I can see it being clicked. it just doesn’t do anything when I click it

Are you getting any errors in the output?

No errors are present either. characters

run a print after the click to make sure it’s clicked. Aswell as, using

local button = instance.new("TextButton",parent)

Is much better than just hiding the button. Destroy the button when done with it.
If you could show us the entire script(s) that’d be great

Yeah I have tried removing, destroying and then cloning the text button again (from a template) and it hasn’t worked either.
button code:

for i,v in pairs(playerFolder:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			if debounce == false then
				debounce = true
				game.MarketplaceService:PromptProductPurchase(player, devProductID)
				game.ReplicatedStorage.RemoteEvent:FireServer(v.Name)
			end 
			debounce = false
		end)
	end
end

Okay, so I don’t believe it’s proper to have the function inside a for loop, I could be wrong on that part. Could you please explain the purpose of the button.

There will as many buttons as the number of players on the server
The button’s function is to kill a player. (ex. I click a random button then the player assigned to that button will be killed)

The function works the first time, but when the script adds a new button (new player joins) it stops working.

Not sure what playerFolder is and why you’re looping through it for text buttons, however, I would suggest just having a local script cloned in each button. Each script will be along the lines of “If I’m clicked, find out who clicked me (the local player) and kill my assigned player (the player in the text)”

2 Likes

playerFolder is where all the visible textbuttons go.
I’ll try having a local script for each, maybe it might work.

It actually worked… inserting local scripts into each and every single one of the buttons.
that was the problem the whole time. I’m gonna revert back to destroying and refreshing now.
Thank you so much man, you don’t know how happy I am.

1 Like

While it may be an operating solution, having multiple scripts can be an extremely bad practice and everything can be controlled from 1 script. Also I recommend avoiding the unused system and sticking to a Destroy/Clone method of a premade template, stored somewhere like replicated storage.

2 Likes