How to disable player spawning when they first died?

So, uh I am currently making this 5v5 FPS game,but am having trouble refraining the player’s character from spawning again when they first died. So uhm, my question right now is how do I disable them from spawning again after they died once?

Also if u dont mind, I wanna ask how do I make a spawn cutscene too?

5 Likes

Disable CharacterAutoLoads and use Player:LoadCharacter() for when you want to spawn a Player.

https://developer.roblox.com/en-us/api-reference/property/Players/CharacterAutoLoads

3 Likes

You can use the “LoadCharacter” function on the Player to only spawn them when you need to. In this case, when they join the game. You can do this by disabling the “CharacterAutoLoads” property in the Players service which automatically loads the player’s character on join and then using the “LoadCharacter” function on the player.

Example code:

local Players = game:GetService("Players")

Players.PlayedAdded:Connect(function(Player)
    Player:LoadCharacter()
end)
8 Likes

o thanks mate! but I also have a question, how do I create a spawn cutscene at the start of the game when they spawn?

You can use TweenService to create a cutscene. TweenService is used to kind of “transition” properties of an object. For example the CFrame of the player’s camera (CFrame contains world position and rotation data). You just need to set up parts where the camera should go to and code the system.

AlvinBlox made a great tutorial on this: Roblox TweenService Tutorial - How To Tween Parts In Your Game - Part Tweening - YouTube

Ah thanks! just What I have been looking for my FPS game :slight_smile:

No problem! Also, I recommend marking one of my replies as a solution because you got an answer.

Ah yes, no worries. Thanks mate for the help

Yeah, and the character will still in the game, you need to put a script in the character like this:

script.Parent.Humanoid.HealthChanged:Connect(function(health)
	if health <= 0 then
		wait(2)
		game.Players:GetPlayerFromCharacter(script.Parent).Character = nil
		script.Parent:Destroy()
	end
end)

If you don’t want it to happen

Problem is, I wanna make it like when they died, they wouldnt be able to spawn but then they would be spectating their teammates, however when I run that script, the camera is uhm just stuck?

I’m not sure if the player character stays in the game. If it does, this code should remove it.

Player.CharacterAdded:Connect(function(Character)
    Character:WaitForChild("Humanoid").Died:Connect(function()
		if Character ~= nil then -- Checks if the player character exists, if it does, destroy it.
            Character:Destroy()
		end
	end)
end)

You can put this code in the same PlayerAdded function which your “LoadCharacter” function is in.

2 Likes

Yes, that is normal. You have to set the camera’s CameraSubject property to the Humanoid object of the player’s character they are spectating. This is best done with a client script. I can provide code if needed.

yes pls, I rlly need the spectate system to only spectate the players in their team and not the other team tho-

You can do this by checking if the spectated player’s team is the player spectating’s team.

Example code:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer -- The player spectating
local PlayerToSpectate = nil -- Let's say this is the player you want to be spectated

if PlayerToSpectate.Team == Player.Team and PlayerToSpectate.Character.Humanoid ~= nil then -- Checks the spectated player's team and if their Humanoid object exists
    game:GetService("Workspace").Camera.CameraSubject = PlayerToSpectate.Character.Humanoid
end

This should be inside a local script.

Would this script below go inside of a Local or Server script?

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    Player:LoadCharacter()
end)