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!
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.
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.
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
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
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
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.
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.
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)?