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?
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.
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.
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)”
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.
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.