I’m trying to make system where if a player dies while the game is currently in-round they will respawn as a creature, but it seems like there is a temporary immunity the player has and the player does not die if I set it’s health to 0 or below within seconds of the character being loaded and remains alive with 0 health (somehow), I just want to know if there is some other more efficient method for respawning/setting the players character ON JOIN or to getting around this temporary immunity the player character has a few moments after loading, I’ve tried using LoadCharacter() but only for it to error and fill up the game with 10 different player models.
I have also tried setting the players health to negative math.huge only for the player to still not die and continue to be playable- I have no idea what is happening.
In the API it says " When the value of the character’s health reaches 0, the [Humanoid] automatically transitions to the Dead [HumanoidStateType]." but if I set the Humanoids health to 0 within a few seconds of the character being loaded for the first time the players HumanoidStateType doesn’t get set to the Dead [HumanoidStateType] and the player is still able to play (with 0 health), I think there is something wrong here.
Don’t use Humanoid:TakeDamage to kill the player, instead use Humanoid.Health = 0
Additionally, you can change the Humanoid’s state to dead: Humanoid.State = Enum.HumanoidStateType.Dead
If all this still doesn’t work, the forcefield spawn locations create might be the issue. You can just wait for it and then destroy it Character:WaitForChild(“ForceField”):Destroy()
I do use Humanoid.Health = 0 but as you can read above it does not work on a newly loaded character, and I just tried to set the state to Enum.HumanoidStateType.Dead but I got an error saying “State is not a valid member of Humanoid “Noobap0.Humanoid””, also all forcefield durations on every spawn is set at 0.
Here is the code for my PlayerAdded function that takes care of all the team changes for players.
It works perfectly aside for if someone joins while in-round, the players team is set correctly but I cannot set their avatar to the creature for the life of me for no apparent reason.
local function PlayerAdded(player)
player.CharacterAdded:Connect(function(character)
local Humanoid = character:WaitForChild("Humanoid")
if InRound.Value == true and player.Team ~= TrollTeam then
player.Team = TrollTeam
Humanoid.State = Enum.HumanoidStateType.Dead
elseif InRound.Value == false and player.Team ~= HumanTeam then
player.Team = HumanTeam
Humanoid.State = Enum.HumanoidStateType.Dead
end
Humanoid.Died:Connect(function()
task.wait(3)
if InRound.Value == true then
local TrollClone = TrollCharacter:Clone()
TrollClone.Name = player.Name
TrollClone.Parent = workspace
player.Character = TrollClone
elseif InRound.Value == false then
if Players[player.Name] then
player:LoadCharacter()
player.Character:WaitForChild("Humanoid").BreakJointsOnDeath = false
player.Character:WaitForChild("Humanoid").RequiresNeck = false
end
end
end)
end)
player:LoadCharacter()
if InRound.Value == true and player.Team ~= TrollTeam then
player.Team = TrollTeam
elseif InRound.Value == false then
player.Team = HumanTeam
end
end
I found out that using ChangeState on a Humanoid only works in LocalScripts for example:
player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Dead)
and game.Workspace."PlayerCharacter".Humanoid:ChangeState(Enum.HumanoidStateType.Dead)
only work client-side, it would’ve been helpful if it said this on the api.
I was able to get it to an acceptable rate of function by sending a remote from inside a Servers-Side PlayerAdded function that loops sending a remote to a local script to set the players health to 0 until the player is identified as dead on the Server-Side.
Here are the scripts that I used for those that are in this post because they encountered the same issue.
Server-side script
local db = false
player:LoadCharacter()
repeat
task.wait(0.1)
until player:HasAppearanceLoaded()
if InRound.Value == true then
player.Team = TrollTeam
player.Character:WaitForChild("Humanoid").Died:Once(function()
db = true
end)
repeat
task.wait(0.1)
StartRemote:FireClient(player)
until db == true
elseif InRound.Value == false then
player.Team = HumanTeam
end
Although this is definitely a bug on Roblox’s end (being unable to kill the player by setting their health to 0 in Server-Side on the players first loaded character in-game) and I hope it is acknowledge and fixed by Roblox’s engineers.