Im having issues with PlayerAdded lately in studios [works in normal game].
I know why this happens, but its still annoying. Is there a way to fix this?
Things i tried:
RunService: IsStudio() | messes up the code, so i wont use this
I developed this block of code over time by testing Roblox examples and several visits to the Dev Forum.
It works consistently:
local Players = game:GetService("Players")
local RESPAWN_DELAY = 5
Players.CharacterAutoLoads = false
local function PlayerAdded(player)
-- added
print("Player Loaded", player)
local function CharacterAdded(character)
-- added
print("Character Loaded", character)
-- died
local humanoid = character:WaitForChild("Humanoid")
local function CharacterDied()
print("Character Died", character)
task.wait(RESPAWN_DELAY)
player:LoadCharacter()
end
humanoid.Died:Connect(CharacterDied)
end
player.CharacterAdded:Connect(CharacterAdded)
player:LoadCharacter()
end
for _, player in Players:GetPlayers() do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
local function PlayerRemoving(player)
-- leaving
local PlayerName = player.Name
print("Player Removing", player.Name)
end
Players.PlayerRemoving:Connect(PlayerRemoving)