I’m trying to get the PlayerGui before the player leaves.
Is there any way?
I’m trying to get the PlayerGui before the player leaves.
Is there any way?
Why? You would only have limited time before the player leaves.
Yes, PlayerRemoving fires BEFORE the player is removed.
I’m trying to do a handcuffs system. But if the player who handcuffed a player leaves, i need to detect if the player handcuffed someone. (The handcuffedPlayer value is on a ScreenGui) so i can release the player.
local function handcuffs(p)
if p.PlayerGui.HandcuffsGUI.PlayerHandcuffed.Value == nil then
print("Nobody Handcuffed")
else
game.ReplicatedStorage.Events.ReleasePlayer(p.PlayerGui.HandcuffsGUI.PlayerHandcuffed.Value)
print("Player Released")
end
end
sorry for the bad explaining lol
Don’t put it in a Gui. Put it somewhere that the server can see it, like on the player instance directly.
It is any better. The server cannot see the contents of PlayerGui. Only the folder. So any Guis in there won’t show. Because they are cloned locally into theere from StarterGui. So yes this is better
Yeah I would recommend against that, it’s likely not a good idea, because the player removing event fires right before the player leaves, by the time you go and try to access the PlayerGui there is no guarentee that it’s still there.
Yeah
Not true, as long as you don’t yield before getting player (and PlayerRemoving passes on Player as a parameter) (though I haven’t tested with getting instances in the player instance, the player instance itself will be there.)
There is a chance it might still be there, but its not a good thing to always rely on wether the PlayerGui “exists” long enough for it to be utilized. I can tell you this first hand when working on datastores for example, where I used to use the the player’s Gui to store data. I know they yield but still, its probably better to handle certain values and such in other places sometimes. (When they need to used in the player removing event)
Thanks for this information, always useful for future projects.
Thanks, i decided to do it like that.
No, not a chance, it’s guaranteed. If you read up on it, it fires before the removal. That’s how almost all saves work, PlayerRemoving save data[Player.UserId]. Never errors. Can’t guarantee children instances of it or if Player will be in GetPlayers() though, never tested it. Maybe you had some other circumstances going on that yielded it or other errors Though I agree that storing stuff in GUI is not proper.
Maybe if it doesn’t yield at all, but My overall point is that, like @incapaxx you have limited time and i would say that time is fairly uncertain, if i recall correctly the PlayerGui can’t not be “accessed” at all after a certain amount of time, try this code in a local 2 player sever and it should give you an error…
game.Players.PlayerRemoving:Connect(function(plr)
wait(5)
print(plr.PlayerGui)
end)
I clearly said
You’re yielding. I’ve also said I haven’t tested getting any children instances of Player after. If you want to test it by removing yield and/or have anything else to say, DM me, this is getting off topic.