How To Give Leaderstats When A Player Wins The Game

Hello, it’s been a while that I am trying to give 100 leaderstats points called Money when a player wins the game. There’s already a “findWinner” section, i don’t really know if it could be useful for what I am trying to do. I’ve tried anything, but still confused on this part.

local parts = game.Workspace.Parts
local gameScript = game.ServerStorage.Script

wait(4)
local function resetChars()
	for _,v in pairs(game:GetService("Players"):GetPlayers())do
		local char = v.Character
		if char then
			char:FindFirstChild("Humanoid").Health = 0
		end
	end
end

local function goToGame()
	for _,v in pairs(game:GetService("Players"):GetPlayers())do
		local char = v.Character
		if char then
			local hrt = char.HumanoidRootPart
			hrt.CFrame = game.Workspace.SpawnPart.CFrame
		end
	end
end


local function inGame()
	for i,v in pairs(game.Players:GetPlayers())do
		local InGame = v:FindFirstChild("InGame")
		InGame.Value = true
	end
end

local function findWinner()
	local winners = {}
	for i,v in pairs(game.Players:GetPlayers())do
		if v:WaitForChild("InGame").Value == true then
			table.insert(winners,v.Name)
		end
	end
	local remoteE = game.ReplicatedStorage.Winners
	remoteE:FireAllClients(winners)
	table.clear(winners)
end


local roundLength = 60
local interLength = 15

local Status = game.ReplicatedStorage.Status
local inRound = game.ReplicatedStorage.inRound

local function rounds()
	while wait()do
		if #game.Players:GetPlayers()<= 1 then
			while #game.Players:GetPlayers()<= 1 do
				wait()
			end
		end
		for i = interLength, 0,-1 do	
			inRound.Value = false
			if i == interLength then
				findWinner()
				wait(2)
				resetChars()
				gameScript.Parent = game.ServerStorage
			end
			wait(1)
			Status.Value = "Intermission: "..i.." Seconds left!"
		end
		goToGame()
		inGame()
		gameScript.Parent = game.ServerScriptService
		inRound.Value = true
		local alive = #game.Players:GetPlayers() 
		Status.Value = "Game: "..alive.." Players Left"
		for i,player in pairs(game.Players:GetPlayers())do
			local char = player.Character
			local humanoid = char.Humanoid
			humanoid.Died:Connect(function()
				alive = alive - 1
				player.InGame.Value = false
			end)
		end
		while alive > 1 do
			wait()
			Status.Value = "Game: "..alive.." Players Left"
		end
	end
end

rounds()

Hope you can help me, thank you!

if v:WaitForChild("InGame").Value == true then
			table.insert(winners,v.Name)
		end

Here, just under table.insert(winners, v.Name), you can change the leaderstats like so:

if v:WaitForChild("InGame").Value == true then
			table.insert(winners,v.Name)
            v:WaitForChild("leaderstats").Money.Value += 100 -- change the number
		end

Hope this helps!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.