Player keeps money after death but loses all if the game ends

I’m new to scripting and most of my scripts came from the dev forum. I am currently working on a wave based PvE shooter and was wondering how to make it so that if a player dies they keep their money but if everyone dies the game will reset and everyones money will be set to 0. I’ve tried looking on google and on the devforum but I could not find any solution that fits my game.

heres how part of the script looks like:

				if v.Name == "spawner" then
					collectionservice:AddTag(v, "spawner")
				end
			end
			for i, v in pairs(game.Players:GetPlayers()) do
				collectionservice:AddTag(v.Character, "Alive")
				v.Character.HumanoidRootPart.CFrame = workspace.Map:FindFirstChildOfClass("Model").Spawn.CFrame
			end
			roundMsg.Value = "Game In Progress"
			zombieCount.Value = #game:GetService("Players"):GetPlayers()
			zombiesAlive.Value = #game:GetService("Players"):GetPlayers()
			wave.Value = 1
			gameInProgress.Value = true
			repeat
				if #collectionservice:GetTagged("Alive") > 0 then
					if zombiesAlive.Value <= 0 then
						wave.Value = wave.Value + 1
						for i, v in pairs(workspace.Map:FindFirstChildOfClass("Model"):GetChildren()) do
							if v.Name == "spawner" then
								collectionservice:AddTag(v, "spawner")
							end
						end
						for i, v in pairs(game.Players:GetPlayers()) do
							collectionservice:AddTag(v.Character, "Alive")
							v.Character.HumanoidRootPart.CFrame = workspace.Map:FindFirstChildOfClass("Model").Spawn.CFrame
						end
2 Likes

this part is not showing the issue btw, we need to see how you handled the currency

1 Like

heres the script for the money

	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"
	local cash = Instance.new("IntValue", folder)
	cash.Name = "Cash"
	cash.Value = 0
end)

game:GetService('Players').PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function(character)

		character:WaitForChild("Humanoid").Died:Connect(function()

			if player.leaderstats.Cash.Value  > 0 then

				wait(1)

				player.leaderstats.Cash.Value = 0

				player.PlayerGui.Death.Message.Visible = false

				player.PlayerGui.Death.Message.Text = ''

				wait(1)

				player.PlayerGui.Death.Message.Visible = false

			end

		end)

	end)

end)