How can I reward points to the winner?

I have been working on a free for all round based fighting game where the last person standing wins the round. The game knows how to reward points to players each time they get a kill, but I also want to make the game reward points to the winner. I tried a bunch of different stuff which I thought might work but they all do absolutely nothing and result in the script not being able to proceed beyond my code. I know this is an easy fix but only to those who know a secret way that I don’t.

Here is the script that determines the winner, now make that winner get rewarded with points!

function teleport(plr)
wait(1)
– destroy player tools
for i,v in pairs(plr.Backpack:GetChildren()) do
if game.ServerStorage.Tools:FindFirstChild(v.Name) then
v:Destroy()
end
end
for i, v in pairs(plr.Character:GetChildren()) do
if v:IsA(“Tool”) then
if game.ServerStorage.Tools:FindFirstChild(v.Name) then
v:Destroy()
end
end
end
if plr.Character:FindFirstChild(“Torso”) then
plr.Character.Torso.CFrame = CFrame.new(game.Workspace.VotingSystem.SpawnBlock.Position+Vector3.new(0,3,0))
elseif plr.Character:FindFirstChild(“UpperTorso”) then
plr.Character.UpperTorso.CFrame = CFrame.new(game.Workspace.VotingSystem.SpawnBlock.Position+Vector3.new(0,3,0))
end
end
game.Players.PlayerRemoving:Connect(function(player)

local name = player.Name
if script.Parent.AlivePlayers:FindFirstChild(name) then
	script.Parent.AlivePlayers:FindFirstChild(name):Destroy()
end

end)

script.Parent.AlivePlayers.ChildRemoved:Connect(function()
local playeronline = 0
for i,v in pairs(game.Players:GetPlayers()) do
playeronline = playeronline+1
end
local noofplayeralive = 0

for i, v in pairs(script.Parent.AlivePlayers:GetChildren()) do
	noofplayeralive = noofplayeralive+1
end
if noofplayeralive==1 then
	local name = "None"
	
	for i,v in pairs(script.Parent.AlivePlayers:GetChildren()) do
		name = v.Name
	end
	
	local winner = "The winner is "..name
	
	--THIS IS WHERE THE SURVIVING WINNER GETS REWARDED 100 POINTS
	
	script.Parent.Disabled = true
	
	local map = game.Workspace.Maps:FindFirstChild(script.Parent.MapChosen.Value)
	local silence = map.sound:Stop()
	
	game.ReplicatedStorage.SendTextToPlayers:FireAllClients("Game Over")
	wait(3)
	game.Workspace.victory:Play()
	print(winner)
	game.ReplicatedStorage.SendTextToPlayers:FireAllClients(winner)
	wait(3)
	
	
	
	
	
	--local leaderstats = script.Parent.AlivePlayers.leaderstats --DIDN'T WORK
	--if name ~= nil and name.Value ~= nil then --DIDN'T WORK
	--leaderstats.Cash.Value = leaderstats.Cash.Value +100 --DIDN'T WORK
	
	
	
	
	
	for i,player in pairs(script.Parent.AlivePlayers:GetChildren()) do
		coroutine.wrap(function()
			local plr = game.Players:FindFirstChild(player.Name)
			game.ReplicatedStorage.BlackScreen:FireClient(plr)
			teleport(plr)
		end)()
		end
	--script.Parent.AlivePlayers.leaderstats.Cash.Value = leaderstats.Cash.Value +100 --DIDN'T WORK
	script.Parent.AlivePlayers:ClearAllChildren()
	if playeronline>1 then
	script.Parent.Disabled = false
	end
end

end)

Go ahead and reply with your own solutions, but if you get confused or need to see what’s inside the game then let me know.

How are you determining the winner of each round?

You can store the winners in a table for each round( generally, in a function or a loop), and once the round has ended, you check how many have survived, and reward each of them in points, etc…

The game checks for players that are still alive under the folder named AlivePlayers, as soon as there is 1 last player the round ends and that player wins.

In that case, as soon as the length of the AlivePlayers folder in a table reaches to 1 you can end the round and reward that one player accordingly

1 Like

That’s what I’m trying to do but I can’t figure out how to actually make it work.

Then its simplier, all you have to do is to check who remains as the last person alive( cus when they die, they are parented back to Workspace). And when the round ends, give that player the reward and make sure to take him out of the folder. Here I’d prefer using tables instead.

This is the game

(6) One Weapon Deathmatch! - Roblox

I will give you all edit access so you can have a closer look inside, I have to leave for an hour or so.

Something like this :

If isRoundOn == false then
for _,player in pairs(game:Players:GetPlayers()) do
If table.find(PlayersAlive, player.Name) then
–reward him.
–remove from table
–new round
end
end

	--local leaderstats = script.Parent.AlivePlayers.leaderstats --DIDN'T WORK
	--if name ~= nil and name.Value ~= nil then --DIDN'T WORK
	--leaderstats.Cash.Value = leaderstats.Cash.Value +100 --DIDN'T WORK

You’re saying this didn’t work, correct? If I’m understanding correctly you’re not actually referencing a player with script.Parent.AlivePlayers, rather just a Folder. Try this right below where you put --THIS IS WHERE THE SURVIVING WINNER GETS REWARDED 100 POINTS

local playerToAward = game.Players:FindFirstChild(name)
playerToAward.leaderstats.Cash.Value = playerToAward.leaderstats.Cash.Value  + 100

I’d also probably add a check in there to see if the player is actually a player in the game, just in case that player left the game before they won or something like that.

1 Like

Who would have thought that my problem can be solved with just 2 simple lines of code, this really does work! Can you also add that extra check in there for me? Then I’ll go ahead and mark you as the solution.

If you want to make sure that the player is in the game before it awards the points, you could add an if statement to check if the player is in the game, and then preform the task. :slight_smile:

if game.Players:FindFirstChild(name) then
	local playerToAward = game.Players:FindFirstChild(name)
	playerToAward.leaderstats.Cash.Value = playerToAward.leaderstats.Cash.Value + 100
end

Do I put else right underneath that if statement or will it work just like that?

If you want something to happen if the player isn’t in the game then you can add an else statement, otherwise it won’t be needed.

It seems to be working so far, I’ll go ahead and mark you as the solution.