I have this function that loops through a folder that hold the players turn order via string values named 'Player1', 'Player2', 'Player3',etc. all the way up to 'Player8'. If the value is empty then the value is removed via a different script. but thats not the issue. Whenever i check for the players name then return the players name and attempt to print the function i get the error ServerStorage.doTurn:31: attempt to concatenate a nil value
This is the function:
local RS = game:GetService("ReplicatedStorage")
local TurnNum = RS.Turn
local function getPlayerTurn()
for i,v in pairs(RS.PlayerOrder:GetChildren()) do
print(TurnNum.Value)
if v.Name == 'Player'.. tostring(TurnNum.Value) then
print(v.Name)
return v.Name
else
TurnNum.Value = TurnNum.Value + 1
wait()
getPlayerTurn()
end
end
end
print(getPlayerTurn().."'s turn")
EDIT: TurnNum gets set to 1 when it reaches 9(making it range from 1 - 8)

4 comments
Please put
Namein the scope ofgetPlayerTurnand not outside of it.Name does indeed server no purpose being out of the for loop. Instead have it end the loop prematurely by returning in it. Also doesn't this have to potential to stack overflow?
I tried what you did and no matter what I do it continues to return nil. I even have it print 'Name' and it prints the correct name but it returns nil. Idk if return is broken or what
what about putting the name as an Arg