So here’s the problem I found (solution below, too 🙂 )
I have trees in Battle Farm that are managed through a series of SurfaceGuis (with buttons to plant, cut down, etc). The Guis are in the player.PlayerGui (since the buttons use LocalScripts) and assigned an Adornee called “Readout”, which is an invisible brick wrapped around the tree trunk:
When there is no tree planted in the spot, that SAME Readout brick has a SurfaceGui that says “Click to Plant”:
And when I first load each tree, they work fine.
HOWEVER – if you
- Click to plant a tree (GUI 1)
- THEN click the “water” button ON THAT SAME TREE (GUI 2) after it’s planted,
- Nothing happens. In a gui that if loaded first (loading a planted tree) works fine.
I tried a lot of things:
- Deleting any SurfaceGuis from player.PlayerGui with the Readout assigned as Adornee using Destroy()
- Trying the same but using game.Debris:AddItem(gui,0)
- Testing for script Disabled, Zindex, etc etc
Ultimately, here’s what worked:
Before swapping out the GUI, I first cloned the readout part, destroyed the old readout part and assigned the GUI to the new (identical) readout part. Lots of extra overhead but it was the only way I could find to fix it.
function tycooncontrol.applyDecalToTreeReadout(player, orig_readout_part, planted_or_unplanted) -- first we're going to try deleting and redoing the readout part for _, gui in pairs(player.PlayerGui:GetChildren()) do if gui.ClassName == "SurfaceGui" and gui.Adornee == orig_readout_part then gui:Destroy() -- destoying any guis attached to the current readout part end end orig_readout_part.CanCollide = false local readout_part = orig_readout_part:Clone() readout_part.Parent = orig_readout_part.Parent orig_readout_part:Destroy()