Give Reward if u have won the Round

Hi everyone I’m currently working on an IDK like Round…System IG and rn I want if the Innocents or the Murderer wins the Winner should get 200 Cash ima show 3 Scripts:(I think the Cash function should get added at the end of the third script

--ModalScript(ReplicatedStrage)


local mmSystem = {}

function mmSystem.ChooseRoles()
	
	local players = game:GetService("Players")
	local playersInGame = {}
	
	for i, p in pairs(players:GetChildren())do
		table.insert(playersInGame, p.Name)
	end
	
	if #playersInGame >= 2 then
		
		local murderer = playersInGame[math.random(1, #playersInGame)]
		table.remove(playersInGame, table.find(playersInGame, murderer))
		
		players:FindFirstChild(murderer):WaitForChild("Role").Value = "Murderer"
		
		for i, plrName in pairs(playersInGame) do
			players:FindFirstChild(plrName):WaitForChild("Role").Value = "Innocent"
		end
		
		--Display Roles for Players
		
		wait(2.5)
		
		for i, playerInRound in pairs(players:GetChildren()) do
			if playerInRound.Team.Name == "Playing" then
				game.ReplicatedStorage.DisplayRole:FireClient(playerInRound)
			end
	     end
		
		wait(5)
		
		local knifeclone = game.ReplicatedStorage.Sword:Clone()
		knifeclone.Parent = players:FindFirstChild(murderer).Backpack
		
		return " Success"
		
	 else
		
		return "Not Enough Players"
	end
	
end

	return mmSystem


















--CashServer(ServerScriptService)


local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("DATA")

local mps = game:GetService("MarketplaceService")

local devProducts = require(game:GetService("ReplicatedStorage"):WaitForChild("DeveloperProducts"))


function saveData(plr:Player)
	
	if not plr:FindFirstChild("DATA FAILED TO LOAD") then
		
		local plrCash = plr.leaderstats.Cash.Value
		
		local success, err = nil, nil
		
		while true do
			
			success, err = pcall(function()
				ds:SetAsync(plr.UserId .. " - Cash", plrCash)
			end)
			
			if not success then
				warn(err)
				task.wait(0.01)
			else
				break
			end
		end
	end
end

function loadData(plr:Player)
	
	local dataFailedWarning = Instance.new("StringValue")
	dataFailedWarning.Name = "DATA FAILED TO LOAD"

	local success, plrData = nil, nil
	
	while true do
		success, plrData = pcall(function()
			return ds:GetAsync(plr.UserId .. " - Cash")
		end)
		task.wait(0.02)
		if not success then
			dataFailedWarning.Parent = plr
			warn(plrData)
		else
			break
		end
	end
	dataFailedWarning:Destroy()
	
	return plrData
end

function setupLeaderstats(plr:Player, savedCash:number)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = savedCash or 0
	cash.Parent = leaderstats
end

function handlePurchase(purchaseInfo)
	
	local plr = game.Players:GetPlayerByUserId(purchaseInfo.PlayerId)
	
	if not plr or plr:FindFirstChild("DATA FAILED TO LOAD") then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local productID = purchaseInfo.ProductId
	
	if devProducts[productID] then
		plr.leaderstats.Cash.Value += devProducts[productID].Cash
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end


game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
	for _, plr in pairs(game.Players:GetPlayers()) do
		saveData(plr)
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	
	local plrData = loadData(plr)
	setupLeaderstats(plr, plrData)
end)





mps.ProcessReceipt = handlePurchase

















--MainRoundScript(ServerScriptService)



-------------------------------------[AUTHOR: reccur]--------------------------------


local intermission = 50
local roundLength = 180

local inRound = game.ReplicatedStorage.InRound
local staus = game.ReplicatedStorage.Status

local playingTeam = game.Teams.Playing
local lobbyTeam = game.Teams.Lobby

local murderMysteryModule = require(game.ReplicatedStorage.MurderMysterySystem)

inRound.Changed:Connect(function()
	
	if inRound.Value == true then
		
		for i, plr in pairs(game.Players:GetChildren()) do
			
			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")
			
			
			
			plr.Team = playingTeam
			
			char:WaitForChild("Humanoid").Died:Connect(function()
				
				plr.Team = lobbyTeam
				
				
			end)
			
		end	
		
		
	else
		
		for i, plr in pairs(game.Players:GetChildren()) do

			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")
			local human = char:WaitForChild("Humanoid")

			humanRoot.CFrame = game.Workspace.lobbySpawn.CFrame
			
			plr.Team = lobbyTeam
			
			human:UnequipTools()
			plr.Backpack:ClearAllChildren()
			
		end
	end	
end)



local function round()	
	while true do
		
		local requiredPlayers = 2
		
		repeat
			wait(1)
			staus.Value = "Atleast ".. requiredPlayers.." players are needed to start a round"
			
		until #game.Players:GetChildren() >= requiredPlayers
		
		inRound.Value = false
		
		
		for i = intermission, 0, -1 do
			
			staus.Value = "Game will start in "..i.." seconds"
			
			wait(1)
			
		end
		
		inRound.Value = true
		
		local msg = murderMysteryModule.ChooseRoles()

		for i = roundLength, 0, -1 do
			
			staus.Value = "Game will end in "..i.." seconds"
			
			local playing = {}
			
			for i, plr in pairs(game.Players:GetChildren()) do
				if plr.Team.Name == "Playing" then
					table.insert(playing, plr.Name)
				end	
			end
			
			local MurdererAlive = false
			local NonMurdererAlive = false
			local murderer
			
			for i, playerInRound in pairs(playing) do
				
				if game.Players:FindFirstChild(playerInRound):WaitForChild("Role").Value == "Murderer" then
					MurdererAlive = true
					murderer = game.Players:FindFirstChild(playerInRound)
					
				elseif game.Players:FindFirstChild(playerInRound):WaitForChild("Role").Value ~= "Murderer" then
					NonMurdererAlive = true
				end
				
			end
			
			
			if #playing == -1 then
				
				staus.Value = "Everyone Has Died"
				
				wait(3)
				break
				
			end
			
			if MurdererAlive == true and NonMurdererAlive == false then
				staus.Value = playing[1].." The Murderer Has Won!"
				wait(3)
				break
			end
			
		    if (MurdererAlive == false and NonMurdererAlive == true) or NonMurdererAlive == true and i == 0 then
	          staus.Value = playing[1].." The Innocents Have Won!"
	          wait(3)
	          break
         end
			
			
			
			wait(1)
		end
		wait(3)
	end
end


spawn(round)
2 Likes
local function awardCash(players, amount)
    for _, plr in pairs(players) do
        if plr and plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Cash") then
            plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + amount
        end
    end
end


local function round()
    while true do
        local requiredPlayers = 2

        repeat
            wait(1)
            staus.Value = "At least " .. requiredPlayers .. " players are needed to start a round"
        until #game.Players:GetChildren() >= requiredPlayers

        inRound.Value = false

        for i = intermission, 0, -1 do
            staus.Value = "Game will start in " .. i .. " seconds"
            wait(1)
        end

        inRound.Value = true
        local msg = murderMysteryModule.ChooseRoles()

        for i = roundLength, 0, -1 do
            staus.Value = "Game will end in " .. i .. " seconds"

            local playing = {}

            for i, plr in pairs(game.Players:GetChildren()) do
                if plr.Team.Name == "Playing" then
                    table.insert(playing, plr)
                end
            end

            local MurdererAlive = false
            local NonMurdererAlive = false
            local murderer

            for _, playerInRound in pairs(playing) do
                local role = playerInRound:WaitForChild("Role").Value
                if role == "Murderer" then
                    MurdererAlive = true
                    murderer = playerInRound
                elseif role == "Innocent" then
                    NonMurdererAlive = true
                end
            end

            if #playing == 0 then
                staus.Value = "Everyone Has Died"
                wait(3)
                break
            end

            if MurdererAlive and not NonMurdererAlive then
                staus.Value = murderer.Name .. " The Murderer Has Won!"
                awardCash({murderer}, 200)
                wait(3)
                break
            end

            if (not MurdererAlive and NonMurdererAlive) or (NonMurdererAlive and i == 0) then
                staus.Value = "The Innocents Have Won!"
                awardCash(playing, 200)
                wait(3)
                break
            end

            wait(1)
        end
        wait(3)
    end
end

spawn(round)
3 Likes

Thank you my Boy it works!!!

2 Likes

I just noticed one thing if ur the murderer and win only the murderer gets the Money but when the Innocents win the Murder gets the Money too I know what the problem is its because instead of innocents there is playing but I tried putting innocents there but it didn’t work I wrote the Text bait goofy I hope u understand

1 Like

hmm… 2 sec

            if (not MurdererAlive and NonMurdererAlive) or (NonMurdererAlive and i == 0) then
                status.Value = "The Innocents Have Won!"
                awardCash(innocents, 200)  -- Only reward the innocents
                wait(3)
                break
            end
2 Likes

I tried that before but it marks innocents blue

1 Like

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