Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make this leadeboard saves your money?

I'm making a game and I need the money to be saved how could I do it?

game.Players.PlayerAdded:Connect(function(player)
	local ls = Instance.new("Folder",player)
	ls.Name = "leaderstats"
	
	local money = Instance.new("IntValue",ls)
	money.Name = "Money"
	
	local cc = Instance.new("IntValue",player)
	cc.Name = "CashCollected"
	
	local robbing = Instance.new("BoolValue",player)
	robbing.Name = "Robbing"
	robbing.Value = false
	
	player.CharacterAdded:Connect(function(char)
		player.Robbing.Value = false
		player.CashCollected.Value = 0
	end)
	
end)

3 answers

Hi Tripyfy,

You just need to use DataStoreService to store it. I won't teach you how to do it, but there are many tutorials on youtube and wiki you can check out. Here is the link to a youtube tutorial that helped me out a lot.

##Hope i helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

Try this script:

local ds = game:GetService("DataStoreService")
game.Players.PlayerAdded:Connect(function(player)
	local data = ds:GetAsync("player_" .. player.UserId) or 0
	local ls = Instance.new("Folder",player)
	ls.Name = "leaderstats"
	local money = Instance.new("IntValue",ls)
	money.Name = "Money"
	money.Value = data
	local cc = Instance.new("IntValue",player)
	cc.Name = "CashCollected"
	local robbing = Instance.new("BoolValue",player)
	robbing.Name = "Robbing"
	robbing.Value = false
	player.CharacterAdded:Connect(function(char)
		player.Robbing.Value = false
		player.CashCollected.Value = 0
	end)
end)
game.Players.PlayerRemoving:Connect(function(player)
	ds:SetAsync("player_" .. player.UserId, player:WaitForChild("leaderstats").Money.Value)
end)

3 comments

0

it doesnt work for me ;8

0

It does NOT work in studio, sorry.

0

Unless if you let studio to access API Services.

This discussion is preserved as it was. New answers, comments, and votes are closed.