Disabling All GUIs When A Player is Kicked

Hey Developers!

I’ve been trying to figure out ways to disable the players GUI when they get kicked from the game. For more context, I’m making a VR-Only game, and I want non-VR players to be kicked, but I have a GUI that shows when the player joins, and when a non-VR player joins, the GUI is still there even after they get kicked.

This is the current code I have for disabling the GUI when the player gets kicked:

game.Players.PlayerRemoving:Connect(function(player)
	for _,gui in pairs(player.PlayerGui:GetChildren()) do
		gui:Destroy()
	end
end)

I don’t know if it’s the script placement, which is placed in StarterPlayerScripts, or the code itself.

If you have any solutions, or suggestions, please let me know!

1 Like

Pretty sure Roblox does that automatically so your script is pointless. When a player is kicked their player instance is destroyed, and thus all the descendants like PlayerGui and all the UIs it contains get destroyed as well.

1 Like

this isn’t going to work because you need to do all the gui client side, try doing a remote event, also if you can provide more detail, like an image of what is happening, so i can try to better understand the problem.

1 Like

Note that I have subtitles in this game, and this is just a snippet:

The issue is I don’t want the subtitles there.

The reason why this is happening is because when a player disconnect their client captures the last thing that it has and leaves it like that. If you want the subtitles to be removed you’ll have to remove them before you kick the player

Do you have any ideas how? Like maybe checking the players UserInputService and then enabling the GUI?

basically you’ll have to go through the script and right before you kick them you have do disable the gui. Like manually put what you had, but before the kick

So something like this?

local Players = game:GetService("Players")
local VRService = game:GetService("VRService")

local LocalPlayer = Players.LocalPlayer

if (not VRService.VREnabled) then
    for _, gui in ipairs(LocalPlayer.PlayerGui:GetChildren()) do
        gui:Destroy()
    end
    return LocalPlayer:Kick("This is a VR only experience! Try and rejoining with a VR Headset connected!")
end
1 Like

yes, did that end up working for you?

1 Like

If you’re kicking them from a LocalScript, hackers can disable that. You need to delete the GUIs in a LocalScript and kick them in a regular one soon after.

1 Like

not if he sets the local script parented to nil instead

1 Like

That’s not how that works. Setting the parent of something to nil doesn’t magically make it invisible, it just means it won’t show up in the object browser. As it turns out, exploiters don’t have the object browser and it doesn’t affect them. What’s more, they can delete Roblox’s Kick code without ever needing to touch your scripts. The only thing you can do about it is to kick them from the server.

No sadly, it didn’t work. Thanks for the help though!

I see what you’re trying to do, have you tried deleting the gui BEFORE kicking them?

Nvm just read more. Sorry

1 Like

Try doing this in ReplicatedFirst

local Players = game:GetService("Players")
local VRService = game:GetService("VRService")

local LocalPlayer = Players.LocalPlayer

if (not VRService.VREnabled) then
	for _, gui in ipairs(LocalPlayer.PlayerGui:GetChildren()) do
		gui:Destroy()
	end
	LocalPlayer.PlayerGui.ChildAdded:Connect(function(gui)
		gui:Destroy()
	end)
	
	return LocalPlayer:Kick("This is a VR only experience! Try and rejoining with a VR Headset connected!")
end

If this doesnt work, I’d suggesting having all UI disabled by default, then in this script enabling them all (on the client or server with a remote event)

Technically since the VR check occurs on the client(through VRService.VREnabled) can’t they just fake that as well(because the server will need some kind of information regarding if a user has VR enabled or not before kicking, which the exploiter can fake)?

try making a local script in replicated first, when the local player is removed delete PlayerGui