How can I do so it gets the player when the player clicks on a button? I have my code down below, but it does not work, please help! Btw, this is a normal script, not a local one.
This is bad practice - you’re assuming an unchanging hierarchy of Player.PlayerGui.x.y.z.Script when the hierarchy could be changed to Player.PlayerGui.x.y.z.w.f.p at runtime. A better solution would be to use FindFirstAncestorWhichIsA() or FindFirstAncestorOfClass(). And, if you’re using a localscript an even better solution would be to use Players.LocalPlayer.
That’s just going to give you a mess in the code, you can just do game.X. (X being the destination) It’s easier and in case of a bug, you can just resolve it immediately. But if we repeat script.Parent.Parent.Parent.Parent(and so on) it’s going to create a mess in our code, and incase of a bug we can’t resolve it because we have a mess. I’ll recommend to get code classes again.
This wouldn’t work for OP’s problem - and it would be just as much of a “mess” in the code. While endlessly typing .Parent until you reach a player object is bad practice, game.Players.x will never work for determining the player who activated a Gui button.