Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make players leave game, on death, and make it so no one can join a server?

I am trying to make a battle royale game, but do not know how to make players leave on death. I also need it so that people, cant join the server, once a match in the server has begun

Can someone script me an example of how to do both of these things, and explain what they did.

Thanks

4 answers

I won't give you the code because I want you to learn from implementing yourself (and that this isn't a site for full script requests), but I'll explain how to do it so you know the basics:

Use the game.Players.PlayerAdded event. When a player joins, check if a certain variable / the game's state is running or not. If it is running, call Player:Kick() on the player.

Really, since you should be using universes for this, you won't have to worry about kicking players who join after, you can just not teleport them in with TeleportService after the round begins.

You can tell when a player dies with the Player.CharacterAdded event and the Humanoid.Died event. After this, you can call TeleportService:Teleport() to teleport them back to the lobby, or Player:Kick() to kick them.

game.Players.PlayerAdded:Connect(function(Player)
	-- your code here!
end)

3 comments

0

oh ok thanks, I get some of it now! I will try it out.

0

wait does it have to be in a local script, or a normal script?

0

This would be done in a Script.

Here is what I tried, and it didnt work.

local humanoid = game.Players.LocalPlayer.Character.Humanoid
local player = game.Players.LocalPlayer


if humanoid.Health ==0 then
	Player:Kick()
end

I put it in StarterPlayerScripts. But when I tried it, the output said that Character was a nil value, plz help

i think i know how to fix it, im not entirely sure

LocalPlayer only works with LocalScripts, not Scripts

an easy fix is to parent the Script in the StarterGui and then use this code i have provided below

local player = script.Parent.Parent local humanoid = player.Character.Humanoid

humanoid.Died:connect(function() player:Kick() end)

--if this doesnt work i sadly cannot help you, sorry

Try Use This Script:

Message = "You died" --Your Message What you want to show when player got kick.

game.Players.PlayerAdded:connect(function(plyr)
	
	
	repeat wait() until plyr.Character ~= nil
	repeat wait() until plyr.Character:FindFirstChild("Humanoid") ~= nil
	
	
	
	plyr.Character.Humanoid.Died:connect(function()
		plyr:Kick(Message)
	end)
	
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.