I made a sword game and i made a function which is giving money to winner. But it doesnt work
local mapstoragechild = game.Workspace.MapStorage:GetChildren() local players = game.Players:GetPlayers() local message = game.Workspace.Message local rp = game.Workspace.MapStorage.Map.PlayerStorage:GetChildren() function tpbak() for i = 1,#rp do rp[i].Humanoid.Health = 0 end end while #mapstoragechild == 1 do local playerleft = game.Workspace.MapStorage.Map.PlayerStorage:GetChildren() function gibmw() local plp = playerleft:GetPlayerFromCharacter() for i = 1, #playerleft do plp[i].leaderstats.Money.Value = plp[i].leaderstats.Money.Value + 10 end end if #playerleft == 1 then gibmw() tpbak() wait(2) game.Workspace.MapStorage:ClearAllChildren() script.Parent.Gameselect.Disabled = true wait(3) script.Parent.Intermission.Disabled = false game.Workspace.Gamemode.Value = 0 message.Value = "Game Ended !" game.Workspace.Songs.Songloop.Disabled = false wait(1) script.Parent.Gameselect.Disabled = false script.Disabled = true break end wait(0.1) end --This script making 1 player left then shut the gametime and tp players and gib rewards
I helped solving and we dont really know what was wrong because i just did an in pairs function to loop throught the remaining players and it worked!
i would change line 14 - 17 to:
for index, player in pairs(players) do player.leaderstats.Money.Value = player.leaderstats.Money.Value + 10 end end