So I was making a script where when the timer ends, the winner(s) will get their reward for winning but when It gets to the reward giving bit of code, it gives me an error.
The script:
local ingamePlayersFolder = game.Workspace:WaitForChild("IngamePlayers"):GetChildren() local winnersFolder = game.Workspace:WaitForChild("Winners"):GetChildren() if #winnersFolder >= 1 or #ingamePlayersFolder >= 1 then stats.Value = "Players win!" if #winnersFolder >= 1 then for i = 1, #winnersFolder do game.Players[#winnersFolder[1]].leaderstats.Bux.Value = game.Players[#winnersFolder[1]].leaderstats.Bux.Value + winnersReward end end
The error:
Workspace.GameController:79: attempt to get length of a Instance value
I found out that I could just get the player from the character through :GetPlayerFromCharacter which solves my problem.
local ingamePlayersFolder = game.Workspace:WaitForChild("IngamePlayers"):GetChildren() local winnersFolder = game.Workspace:WaitForChild("Winners"):GetChildren() if #winnersFolder >= 1 or #ingamePlayersFolder >= 1 then stats.Value = "Players win!" if #winnersFolder >= 1 then for i = 1, #winnersFolder do local winnerPlr = game.Players:GetPlayerFromCharacter(winnersFolder[1]) winnerPlr.leaderstats.Bux.Value = winnerPlr.leaderstats.Bux.Value + winnersReward print("success_winner") end end end