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 add more currencies to my datasaving script?

``local dataStore = game:GetService("DataStoreService"):GetDataStore("MushroomsData")

starterMushrooms = 0 --This is the starter money

game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local money = Instance.new("IntValue")
money.Name = "Mushrooms"
money.Value = dataStore:GetAsync(plr.UserId) or starterMushrooms
money.Parent = leaderstats

end)

game.Players.PlayerRemoving:Connect(function(plr)

dataStore:SetAsync(plr.UserId, plr.leaderstats.Mushrooms.Value)

end)``

1 comment

0

I really need another currency which is "Cash" but aint getting it work pls anyone help

1 answer

save data

dataStore:SetAsync(plr.UserId, {value1 = plr.leaderstats.Mushrooms.Value; value2 = plr.leaderstats.Cash.Value})

get data

-- make multipl value in leaderstat
local cash = Instance.new('IntValue',leaderstats)
cash.Name = 'cash'
local mushrooms = Instance.new('IntValue',leaderstats)
mushrooms.Name = 'Mushrooms'

local data = dataStore:GetAsync(player.UserId)

if data then -- get data and set value
	local mushrooms, cash = dataStore:GetAsync[1],datastore:GetAsync[2]
	mushrooms.Value = mushrooms
	cash.Value = cash
end

1 comment

0

I tested but now i think theres a little problem.. When i run the game(also in test) it types: ServerScriptService.Script:11: Expected '(', '{' or when parsing function call, got '[' in the output

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