Winner team currency awarding

So yeah this is really complicated but i couldn’t figure it out, im not expecting any answer due how messy this thing is but this is my las t resort before giving up

The thing is i got this currency system that is loaded into the player in a folder is a invalue
it is located inside the player in a folder call TPK the name of the currency is TPP every thing is fine with this, the thing is in this BrickBattle map there is a service that gives the winner 100 player points so i was wondering if i could replace those player points for my currency. but i couldn’t do it, i manage to make it so it fives currency after the game finishes but i want it so it gives it only to the winner.

here is the original script

PlayersRequiredToStartAwardingPoints=1

local y=workspace:GetDescendants()

for s=1,#y do
	if y[s].Name=="Doomspires" then
		
		-- GAME VALUES --
		local GVF=Instance.new("Folder")
		GVF.Parent=y[s]
		GVF.Name="GameValues"
		local TF=Instance.new("Folder")
		TF.Parent=GVF
		TF.Name="Teams"
		local TeamsLeftInt=Instance.new("IntValue")
		TeamsLeftInt.Parent=GVF
		TeamsLeftInt.Name="TeamsLeft"
		local k=y[s]:GetChildren()
		for o=1,#k do
			if not k[o]:IsA("Script") then -- Only make values 
				if k[o].Name~="GameValues" then
					if k[o].Name~="Holder" then
					
						local BCV=Instance.new("BrickColorValue")
						BCV.Parent=TF
						BCV.Name=k[o].Name
						
						local SpawnVal=Instance.new("IntValue")
						SpawnVal.Parent=BCV
						SpawnVal.Name="Spawns"
						
						local u=k[o]:GetDescendants()
						for h=1,#u do
							if u[h]:IsA("SpawnLocation") then
								BCV.Value=u[h].TeamColor
								SpawnVal.Value=#u[h].Parent:GetChildren()
							end
						end
						
					end
				end
			end
		end
		TeamsLeftInt.Value=#TF:GetChildren()
		
		-- GAME CONTROL --
		local x=y[s]:GetDescendants()
		for i=1,#x do
			if x[i]:IsA("SpawnLocation") then
				x[i].AncestryChanged:connect(function(SpawnPart) -- Technically this just checks for changes in parentage, but it also works when the spawn falls into the void. 
					local c=y[s]:WaitForChild("GameValues",1):WaitForChild("Teams",1):GetChildren() -- values are being created inscript, using WaitForChild to avoid syntax errors 
					for g=1,#c do -- Begin scanning in order to associate the GameValues with the actual game
						
						if SpawnPart:IsA("SpawnLocation") then
							if c[g].Value==SpawnPart.TeamColor then -- If one of the BrickColorValues in GameValues.Teams is equal to the SpawnLocation's TeamColor (NOT the spawn's BrickColor), then ...
								
								c[g]:WaitForChild("Spawns",1).Value=c[g]:WaitForChild("Spawns",1).Value-1 -- ... subtract that team's spawn value in GameValues.Teams.[TeamName]. Remember, this is if one of the spawns is deleted.
								
								if c[g]:WaitForChild("Spawns",1).Value==0 then -- If you have no spawns left, then you lose.
									
									y[s]:WaitForChild("GameValues",1):WaitForChild("TeamsLeft",1).Value=y[s]:WaitForChild("GameValues",1):WaitForChild("TeamsLeft",1).Value-1 -- This is vital to the game ending as a whole.
									
									game.Teams:FindFirstChild(c[g].Name).AutoAssignable=false
									local msg=Instance.new("Message")
									msg.Text=c[g].Name.." TEAM has been eliminated!"
									msg.Parent=workspace
								end
							end
						end
						
						if y[s]:WaitForChild("GameValues",1):WaitForChild("TeamsLeft",1).Value==1 then -- If 1 team remains then...
							local e=y[s]:WaitForChild("GameValues",1):WaitForChild("Teams",1):GetDescendants()
							for j=1,#e do
								if e[j].Name=="Spawns" then
									if e[j].Value~=0 then -- ... find that team, whose spawn does NOT have a value of zero ...
											wait(4)
										local msg=Instance.new("Message")
										msg.Text=e[j].Parent.Name.." TEAM has won the game!" 
										local p=game.Players:GetChildren()
										for q=1,#p do
											if #p>=PlayersRequiredToStartAwardingPoints then -- if there's more than 4 people playing lmao
												if e[j].Parent and p[q].TeamColor==e[j].Parent.Value then
													pcall(function() game:GetService("PointsService"):AwardPoints(p[q].userId, 100) end)
												end
											end
										end
										msg.Parent=workspace
											
										script.RegenScriptLocation.Value.Signal.Value=true -- ... regen the map using the Changed function. 
										
										return
									end
								end
							end
						end	
					end
				end)
			end
		end
	end
end
2 Likes

Since you have your currency stored as an IntValue, replace that line with code that adds X amount of currency to p[q].TPK.TPP.Value (and it should only award the currency to winners because the code checks whether the user is on the winning team).

3 Likes