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)---

game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue", p)
stats.Name = "leaderstats"
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
cash.Value = 0
while true do
wait(30)
cash.Value = cash.Value + 50
end
end)

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

local DSService = game:GetService("DataStoreService"):GetDataStore("vincentthecat1")
game.Players.PlayerAdded:Connect(function(Plr)

local uniquekey = 'id-'..Plr.userid
local LeaderBoard = Instance.new('IntValue',Plr)
local savevalue = Instance.new('IntValue')
LeaderBoard.Name = 'LeaderBoard'
savevalue.Parent = LeaderBoard
savevalue.Name = 'Cash'
end)
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

local DataStoreService = game:GetService("DataStoreService")


game.Players.PlayerAdded:Connect(function(Player)
local Intvalue = Instance.new("IntValue")
Intvalue.Value = DataStoreService:GetAsync(Player.UserId) --To Get Whatever data you saved
Intvalue.Parent = workspace
Intvalue.Name = Player.UserId
end)


game.Players.PlayerRemoving:Connect(function(Player)
    local ValueToSave = game.Workspace[Player.UserId]

    ValueToSave:SetAsync(DataStoreService,Player.UserId)
end)

Ad

Answer this question