How to make an invest money system roblox

So I tried searching on YouTube for how to do this but nothing showed so I tried to do this myself after a certain amount of seconds after you invest you get doubled the money. But I’m bad at scripting

If anyone knows anything like this please send me it thx!

	script.Parent.Parent.Leaderstats.Cash.Take.Money.Away = "150"
	
	wait(10) then
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Leaderstats.Cash.Give.Money.Away = "250"
	  end	
	end
end)
1 Like

What do you want it to do, explain what you want it to do.

1 Like

Ok so you click and it takes money away from you like 150 and you wait a bit and it doubles your money

I can’t provide code as I am on my iPad but you need to simplify the name
Local leaderboard = Game.leaderboard.-name of leaderboard-
Leaderboard.value = 250
Wait (10)
Leaderboard.value = leaderboard.value *2

1 Like

so this

leaderboard.value = 250

wait (10)

leaderboard.value = leaderboard.value *2

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Leaderstats.Cash.Take.Money.Away = "150"
	
	wait(10)
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Leaderstats.Cash.Give.Money.Away = "250"
	  end	
	end
end)

No, just copy The code and format it correctly

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Leaderstats.Cash.Take.Money.Away = "150"

	wait(10)
	script.Parent.MouseButton1Click:Connect(function()
		script.Parent.Parent.Leaderstats.Cash.Give.Money.Away = "250"

leaderboard.value = 250

wait (10)

leaderboard.value = leaderboard.value *2

	end	
	end
end)

This is all of the code you need, please test it as I can’t as I am on ipad

1 Like

I tried and nothing the output says nothing and it don’t take the money away

What is the name of the leaderboard, I will try tomorrow if I can’t do it now

As in currency its cash the name is Cash. if you talking about what makes it a leader boards its in another code with some other code

I will work it out tomorrow and try the code as it it is hard when I can’t see your screen

1 Like

What does the Leaderstats folder look like?

local ds = dss:GetDataStore("GameData")

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"

	local plrkey = "id_"..player.UserId
	local data = ds:GetAsync(plrkey) or {}

	local cash = Instance.new("IntValue",leaderstats)
	cash.Name = "Cash"
	cash.Value = data[1] or 2000

	local kills = Instance.new("IntValue",leaderstats)
	kills.Name = "Kills"
	kills.Value = data[2] or 0

	--Kills And Cash Etc
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function(killed)
			print("Died")
			local CreatorTag = character.Humanoid:FindFirstChild("creator")
			print(CreatorTag)
			if CreatorTag and CreatorTag.Value then

				local stats = CreatorTag.Value:WaitForChild("leaderstats")

				stats["Cash"].Value += 20
				stats["Kills"].Value += 1   
			end
		end)
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.UserId, {plr.leaderstats.Cash.Value, plr.leaderstats.Kills.Value})
end)

game:BindToClose(function()
	for i, plr in pairs(game.Players:GetPlayers()) do
		ds:SetAsync("id_"..plr.UserId, {plr.leaderstats.Cash.Value, plr.leaderstats.Kills.Value})
	end
end)

This helps a lot! When your money is doubled, does it double based on the amount of money you had before you invested or after?

1 Like

It doubles after 10 seconds after you pressed to get rid of money

local cash = script.Parent.Parent.Leaderstats.Cash.Give.Money.Away 
---[[making a variable so I don't have to type alot everytime I need to say cash
script.Parent.MouseButton1Click:Connect(function()
     wait(10) -- waiting 10 seconds after click
	 cash = cash*2 --doubling cash
end

I think I know that you mean but I want to be sure. Let’s say you had 100 coins. The cost to invest is 10 coins. You invest and now you have 90 coins. After 10 seconds, your coins are doubled. Do you have 200 coins at the end or 180 coins at the end?

200 at the end of it so like this invest 10 so u got 0 then it gives you 20

1 Like

I’m pretty sure they mean you deposit x, and then you click, and then you get 2x in return. Don’t think of it as a fee, rather a deposit.

1 Like