Guys I've Mode money for race winner but The last player alive cannot take money pls someone fix it
LastWinners={}
addEvent("onPlayerDestructionDerbyWin",true)
addEventHandler("onPlayerDestructionDerbyWin",getRootElement(),
function (winner)
local account = getPlayerAccount(winner)
if not (isGuestAccount(account)) then
if getPlayerCount() >= 4 then
local WinStreak = 0
local thePlayer = winner
LastWinners[20] = LastWinners[19]
LastWinners[19] = LastWinners[18]
LastWinners[18] = LastWinners[17]
LastWinners[17] = LastWinners[16]
LastWinners[16] = LastWinners[15]
LastWinners[15] = LastWinners[14]
LastWinners[14] = LastWinners[13]
LastWinners[13] = LastWinners[12]
LastWinners[12] = LastWinners[11]
LastWinners[11] = LastWinners[10]
LastWinners[10] = LastWinners[9]
LastWinners[9] = LastWinners[8]
LastWinners[8] = LastWinners[7]
LastWinners[7] = LastWinners[6]
LastWinners[6] = LastWinners[5]
LastWinners[5] = LastWinners[4]
LastWinners[4] = LastWinners[3]
LastWinners[3] = LastWinners[2]
LastWinners[2] = LastWinners[1]
LastWinners[1] = thePlayer
if LastWinners[1] == thePlayer then
WinStreak = 1
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer then
WinStreak = 2
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer then
WinStreak = 3
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer then
WinStreak = 4
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer then
WinStreak = 5
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer then
WinStreak = 6
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer then
WinStreak = 7
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer then
WinStreak = 8
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer then
WinStreak = 9
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer then
WinStreak = 10
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer then
WinStreak = 11
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer then
WinStreak = 12
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer then
WinStreak = 13
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer then
WinStreak = 14
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer then
WinStreak = 15
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer then
WinStreak = 16
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer then
WinStreak = 17
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer and LastWinners[18] == thePlayer then
WinStreak = 18
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer and LastWinners[18] == thePlayer and LastWinners[19] == thePlayer then
WinStreak = 19
if LastWinners[1] == thePlayer and LastWinners[2] == thePlayer and LastWinners[3] == thePlayer and LastWinners[4] == thePlayer and LastWinners[5] == thePlayer and LastWinners[6] == thePlayer and LastWinners[7] == thePlayer and LastWinners[8] == thePlayer and LastWinners[9] == thePlayer and LastWinners[10] == thePlayer and LastWinners[11] == thePlayer and LastWinners[12] == thePlayer and LastWinners[13] == thePlayer and LastWinners[14] == thePlayer and LastWinners[15] == thePlayer and LastWinners[16] == thePlayer and LastWinners[17] == thePlayer and LastWinners[18] == thePlayer and LastWinners[19] == thePlayer and LastWinners[20] == thePlayer then
WinStreak = 20
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
local pAlive = getAliveRacePlayers()
local pDead = getDeadRacePlayers()
local WinS = tonumber(getAccountData(account,"highestWinstreak"))
if WinS < WinStreak then
setAccountData(account,"highestWinstreak",WinStreak)
end
if WinStreak >= 2 then
local WinStreakToExport = WinStreak
call(getResourceFromName("race"), "setWinStreakOnMessege", WinStreakToExport)
end
local cashToWin = tonumber((moneyEarnPart*getPlayerCount())*WinStreak)
local playerCash = tonumber(getAccountData(account,"cash"))
if not (cashToWin < 0) then
setAccountData(account,"cash",playerCash+cashToWin)
end
local points = math.floor(((pAlive + pDead)*pDead)*WinStreak)
if not (points < 0) then
local playerPoints = getAccountData(account,"points")
setAccountData(account,"points",playerPoints+points)
end
addStat(account,"mapsWon",1)
if mapType == "DM" then
addStat(account,"DMwins",1)
elseif mapType == "DD" then
addStat(account,"DDwins",1)
scoreboardRefresh(winner)
end
local thePlayer = winner
scoreboardRefresh(thePlayer)
end
end)
-------------------
-- Other race ranks
-------------------
function earnMoney()
local thePlayer = source
local position = (getAliveRacePlayers() + 1)
local account = getPlayerAccount(thePlayer)
if not (isGuestAccount(account)) then
if getPlayerCount() >= 4 then
local pAlive = getAliveRacePlayers()
local pDead = getDeadRacePlayers()
local finalCash = 0
if not (position == 1) then
if pAlive == 0 then pAlive = 1 end
if not respawnFix[thePlayer] then
local finalCash = math.floor(((40/position)*pDead)*pAlive) -- Calculate the final money value.
local points = math.floor((pAlive + pDead)*pDead)
local playerCash = getAccountData(account,"cash")
local playerPoints = getAccountData(account,"points")
setAccountData(account,"points",playerPoints+points)
setAccountData(account,"cash",playerCash+finalCash)
local playerCash = getAccountData(account,"cash")
local playerPoints = getAccountData(account,"points")
addStat(account,"totalDeaths",1)
respawnFix[thePlayer] = true
end
end
end
scoreboardRefresh(thePlayer)
end
end
addEventHandler ("onPlayerWasted",getRootElement(),earnMoney)