Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I have a data Store, but why wont it work?

Asked by 5 years ago

---Important Things---

So I have a LeaderBoard and a Data Store that seems to not work with the LeaderBoard, but why? What went wrong in the scripts?

---Locations--- -TheData Store Script is in the ServerScriptService. -The Leaderboard is in the ServerScriptService.

---LeaderBoard (Working)---

01game.Players.PlayerAdded:connect(function(p)
02local stats = Instance.new("IntValue", p)
03stats.Name = "leaderstats"
04local cash = Instance.new("IntValue", stats)
05cash.Name = "Cash"
06cash.Value = 0
07while true do
08wait(30)
09cash.Value = cash.Value + 50
10end
11end)

---Data Store(Not Working)---

01local DSService = game:GetService("DataStoreService"):GetDataStore("vincentthecat1")
02game.Players.PlayerAdded:Connect(function(Plr)
03 
04local uniquekey = 'id-'..Plr.userid
05local LeaderBoard = Instance.new('IntValue',Plr)
06local savevalue = Instance.new('IntValue')
07LeaderBoard.Name = 'LeaderBoard'
08savevalue.Parent = LeaderBoard
09savevalue.Name = 'Cash'
10end)
1
I do not see any effort to save or get data. Read up: https://developer.roblox.com/en-us/articles/Data-store Shawnyg 4330 — 5y
0
Lacking critical information, making it very hard, if not impossible to fix your script. SCP774 191 — 5y

1 answer

Log in to vote
3
Answered by 5 years ago

I don't see any way you are saving data

if you wanted to save a data you either do :SetAsync or :UpdateAsync

for example

01local DataStoreService = game:GetService("DataStoreService")
02 
03 
04game.Players.PlayerAdded:Connect(function(Player)
05local Intvalue = Instance.new("IntValue")
06Intvalue.Value = DataStoreService:GetAsync(Player.UserId) --To Get Whatever data you saved
07Intvalue.Parent = workspace
08Intvalue.Name = Player.UserId
09end)
10 
11 
12game.Players.PlayerRemoving:Connect(function(Player)
13    local ValueToSave = game.Workspace[Player.UserId]
14 
15    ValueToSave:SetAsync(DataStoreService,Player.UserId)
16end)
Ad

Answer this question