Hello everyone, So, I copied code from DataStore and I would like to define a sum of money but my tests don't work, I don't know how to do it.
local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = Player local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Parent = leaderstats local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(Player.UserId.."-cash") end) if success then cash.Value = data else print("There was an error whilst getting your data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(Player) local success, errormessage = pcall(function() myDataStore:SetAsync(Player.UserId.."-cash", Player.leaderstats.Cash.Value) end) if success then print("Data successfully saved") else print("There was an error when saving data") warn(errormessage) end end)
I tryed:
local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Parent = leaderstats cash.Value = 1000
But it doesn't work, help me please
Hello, if by "define" you mean set a specific amount of currency to the player when you join the game, so for example, the player starts with a certain amount, add this to line 12 of your script;
cash.Value = 1000
If you don't mean this, and mean that you wish to test this datastore, then when you "run" or "server test" the game, open the Menu>Settings>(Scroll to the Bottom)Dev Consol>Server And on the "Command Line" at the bottom type the following line;
game.Players.USERNAME.cash.Value = NUM
Where USERNAME is your ROBLOX Username, and NUM is the amount.
Please comment below if you have any questions ,or if I didn't answer what you wished!