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

How do I load my saved data?

this is the code I have so far

local DS1 = game:GetService("DataStoreService"):GetDataStore("Coins")
local DS2 = game:GetService("DataStoreService"):GetDataStore("Gems")
local DS3 = game:GetService("DataStoreService"):GetDataStore("equippedKnife")
local DS4 = game:GetService("DataStoreService"):GetDataStore("equippedGun")

game.Players.PlayerAdded:connect(function(player)
	
	local stats = Instance.new("IntValue", player)
	stats.Name = "leaderstats"
	
    local coins = Instance.new("IntValue", stats)
	coins.Name = "Coins"
	coins.Value = 50
	
	local gems = Instance.new("IntValue", stats)
	gems.Name = "Gems"
	gems.Value = 0
	
	local inGame = Instance.new("BoolValue", player)
	inGame.Name = "InGame"
	
	local equippedKnife = Instance.new ("StringValue", player)
	equippedKnife.Name = "equippedKnife"
	equippedKnife.Value = "Default"
	
	local equippedGun = Instance.new("StringValue", player)
	equippedGun.Name = "equippedGun"
	equippedGun.Value = "Default"
	
	while wait(60) do
	    DS1:SetAsync(player.userId.."_DS1", coins.Value)
		print("Saved Coins")
		--Saved Coins
		DS2:SetAsync(player.userId.."_DS2", gems.Value)
 		print ("Saved Gems")
		--Saved Gems
		DS3:SetAsync(player.userId.."_DS3", equippedKnife.Value)
		print ("Saved knifeEquipped")
		--Saved equipped Knife
		DS4:SetAsync(player.userId.."_DS4", equippedGun.Value)
		print ("Saved gunEquipped")
		--Saved equipped Gun
	  end
end)

how would I load the stats everytime rather than just saving it?

3 comments

0

Give me the code not a link to a guide, sorry but I am lazy and have already looked through most.

0

This is a website that helps people with scripting, not fulfill their requests to code for them.

0

sorry

1 answer

✓ Accepted answer
DS1:GetAsync(player.UserId)

Thats it! Very easy. Lol

1 comment

0

thanks, how would I make it so that if they were new the "equippedKnife" and "equippedGun" values are "Default"?

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