Hello! I’m trying to make a script, which automatically teams any player to a specific team, after they died.
The teaming itself works, however there comes the issue. All of the in-game player’s cameras get bugged (I’m using Carbon Engine FPS system for more context). It basically makes them see their character from inside while still showing them the normal first person.
Any idea how this could be fixed?
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
repeat wait() until player.CharacterAppearanceLoaded
player.Team = game:GetService("Teams").Dead
end)
end)
end)
That doesn’t gonna work how I want it though… The player should be teamed to the team only when they die, not when they first join. A different team is AutoAssignable already.
This seems to be an issue with the framework you’re using, because this code would work fine. One thing I’d change is to place this code in a script that is in the StarterCharacterScripts folder in the StarterPlayer service:
local character = script:FindFirstAncestorWhichIsA('Model')
local player = game:GetService('Players'):GetPlayerFromCharacter(character)
local humanoid = character:WaitForChild('Humanoid', 5)
if humanoid and humanoid:IsA('Humanoid') then
humanoid.Died:Connect(function()
player.Team = game:GetService('Teams'):FindFirstChild('Dead')
end)
end
Check anything in the Carbon Engine FPS system that is related to the CurrentCamera and anything to do with RenderStepped, Stepped, or Heartbeat using the Find All / Replace All tool which can be found on the View tab in Roblox Studio.
You may find some parts of the code that run without acknowledging the death of the character.