Output [string "stdin"]:8: 'then' expected near 'return'attempt to call a nil value
I don't understand why my easy script is not working. In other languages I program in, there's no such thing as "then".
local getPlayer = function(playerName) local players = game.Players:GetPlayers() for index = 1, #players do local name = players[index].Name:upper() if name:find(playerName:upper()) --removed then return players[index] -- returns player at `index` end end end
if condition then execute end
then indicates the end of your condition, and everything after indicates what would run after the assessment/evaluation.
local getPlayer = function(playerName) local players = game.Players:GetPlayers() for index = 1, #players do local name = players[index].Name:upper() if name:find(playerName:upper()) then -- added then return players[index] -- returns player at `index` end end end