Not being able to give cash and win point in a round system

local function Round()
	while true do
		wait()
		InRound.Value = false
		
		for i = IntermissionLength, 0, -1 do
			Status.Value = "Round will start in "..i.." seconds"
			wait(1)
		end
		
		InRound.Value = true
		
		for i = roundLength, 0, -1 do
			Status.Value = "Round will end in "..i.." seconds"
			
			local PlayersPlaying = {}
			
			for i, v in pairs(game.Players:GetChildren()) do
				if v.Team.Name == "Playing" then
					table.insert(PlayersPlaying, v.Name)
				end
			end
			
			if #PlayersPlaying == 1 then
				for i, v in pairs(PlayersPlaying) do
					local player = game.Players:FindFirstChild(v)
					player.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 100
					player.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1
				end
			end
			wait(1)
		end
	end
end

spawn(Round)

so at the last part about giving cash, it keeps saying image

i tried other ways to solve it but it doesnt work, anything i can do to fix this?

2 Likes

try player.leaderstats.Cash.Value += number

1 Like
if #PlayersPlaying == 1 then
	local player = game.Players:FindFirstChild(PlayerPlaying[1])
	player.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 100
	player.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1
	return
end

This one might works

3 Likes

I prefer doing it this way so I can make changes to the reward at any time if needed before its rewarded.

local reward = 100
if #PlayersPlaying == 1 then
	local winningPlayer = game.Players:FindFirstChild(PlayersPlaying[i])
	if winningPlayer then
		winningPlayer.leaderstats.Cash.Value += reward
		winningPlayer.leaderstats.Wins.Value += 1
		break
	else
		warn("Failed to reward ", PlayersPlaying[1], ", did they leave server?")
		break
	end
end

Then you can break the ‘roundlength’ loop after the reward has been rewarded to the player, so the next round cycle can begin.

2 Likes

The reason this didn’t work is because you were passing a player object as an argument to “FindFirstChild()” in an attempt to find the player (even though you already had the player object), which resulted in the function returning nil. FindFirstChild() is a function which expects a single string value argument, and with this argument attempts to locate a child which has a name matching to that of the string value. You could have fixed your issue by replacing “v” with “v.Name” which would have accessed the value of the “Name” property of the player, you could have also simply used “v” instead since that was a reference to the player object or you could have resolved the issue by using the fix seen in the previous two replies.