I am using char = player.Character or player.CharacterAdded:Wait()
But for some reason it doesnt work.
Here is the relevant part of the code
game.Players.PlayerAdded:Connect(function(player)
player:LoadCharacter()
local plChar = Instance.new("ObjectValue")
plChar.Name = "PlCharacter"
plChar.Value = player.Character or player.CharacterAdded:Wait()
plChar.Parent = game.ServerStorage
plChar.Value:WaitForChild("Humanoid").Died:Connect(function()
plChar.Value:Remove()
game.Workspace.StartSpawn.Position = game.Workspace.EndRoom.SpawPos.Position
task.wait(3)
player:LoadCharacter()
plChar.Value = player.Character or player.CharacterAdded:Wait()
game.ReplicatedStorage.SoundEvent:FireClient(player, false)
plChar.Value:WaitForChild("Humanoid").Died:Connect(function()
print("Final Death")
end)
end)
end)
print("Starting")
task.wait(5)
local char = game.ServerStorage:WaitForChild("PlCharacter").Value
print(char.Name)
local pl = game.Players:GetPlayerFromCharacter(char)
print(pl.Name)
It brings up different errors at random. One error is that It says print(char.Name) is nil, and when I look in the explorer, PlCharacter.Value is also nil for some reason.
Sometimes it PlCharacter.Value sets to the character, but then it says that print(pl.Name) is nil, so it now for some reason cant get the player from the character.
Honestly have no Idea why this is happening.