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