So, I've got a big advanced minigame system. And I've only got 1 problem at the moment. (Pfew).
Let me first write down the script parts I'm going to be talking about.
local PlayerList = workspace.PlayerList
function GetWinningPlayer()
local PlayersInPlayerList = game.Workspace.PlayerList:GetChildren()
for i,Player in pairs(PlayersInPlayerList) do
print('Winning player = ',Player.Name)
return Player.Name
end
function TeleportPlayers(CurrentMap)
for i,player in pairs(Services.Players:GetChildren()) do
wait()
databaseUtils.updateXP(player, 10)
player.Character.HumanoidRootPart.CFrame = CurrentMap.Spawns:GetChildren()[math.random(1,#CurrentMap.Spawns:GetChildren())].CFrame * CFrame.new(0,3,0)
table.insert(InGame,player)
player.PlayerData.InGame.Value = true
player.Character.Head.Transparency = 1
PlayersRemaining.Value = PlayersRemaining.Value + 1
local SV = Instance.new('StringValue')
SV.Parent = PlayerList
SV.Name = player.Name
SV.Value = PlayersRemaining.Value
print('PlayersRemaining.Value = ',PlayersRemaining.Value)
for i,part in pairs(player.Character:GetChildren()) do
if part:IsA('Hat') then
part:remove()
end
end
pcall(function()
player.Character.Head.face:remove()
end)
end
end
In the script below is where it goes wrong
if PlayersRemaining.Value == 1 then
PickedWinner = GetWinningPlayer()
print('PickedWinner = ',PickedWinner) -- Here it prints the name correctly.
Winner = game.Players:FindFirstChild(PickedWinner.Name) -- Here i want to 'select' the player in Game.Players, so i can do additional things
print('Winner = ',Winner) -- And here it prints Nil
So, the functions all together is to pick the 'last man standing'. So the only player left in 'PlayerList' In the last function i call the function to pick the last standing player through "GetWinningPlayer()" The value it returns, is correct. It indeed selects the last man standing. But, once i want to find the Player in game.Players, it says Winner = nil.

4 comments
The GetWinningPlayer function returns the Name of the Player Object already.
I don't wish to be rude, but your code is pretty deprecated and can use some efficiency boosts before utilizing it as a large system.
If you would like some help with that, you can contact my discord in my bio~!
Big oof. Your right. Removing '.Name' from Return fixed it. Thanks!