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

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

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

2 comments

1

I do not see any effort to save or get data. Read up: https://developer.roblox.com/en-us/articles/Data-store

0

Lacking critical information, making it very hard, if not impossible to fix your script.

1 answer

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)

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