Buttons with certain name don't get recognized?

so I have this button called “Destroy” where if clicked it will preform certain action. I also decided to add a tween animation on it when its clicked. however, it gives an error ‘Unable to cast value to Object’ when I try to tween it. it works fine if I rename it to anything OTHER than “Destroy”, like Destroy2, and even “destroy” (notice the capitalization)
what is going on

code?

TweenService:Create(Gui.Destroy,TweenInfo.new(0.1),{Size = UDim2.new(1,0,1,0)}):Play()

This is the part where there is an error, Gui.Destroy is a button
if i rename the button to something else it works tho…

I think it interprets Gui.Destroy as literally the Gui’s Destroy function, try doing Gui:FindFirstChild(“Destroy”)

wait that actually worked lol
i thought destroy was :Destroy not .Destroy()???

Doing it with a : is the same as doing . but passing self as the first argument
These do the same thing:

Gui:Destroy()
Gui.Destroy(Gui)

You can also do something like

game.destroy(some.instance.you.wanna.destroy)

which I find to be very cursed

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.