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

Why aren't some parts of DataStore working?

Why doesn't this XP and XpNeeded and debounce DataStore work? PS. I put my DataStore keys hidden, so I made them random.

RebirthData = game:GetService("DataStoreService"):GetDataStore("ddddeee232")

  

XpData = game:GetService("DataStoreService"):GetDataStore("trreeee23232")

KillsData = game:GetService("DataStoreService"):GetDataStore("awesoemee22")

  

DeathsData = game:GetService("DataStoreService"):GetDataStore("day123334")

  

LvlData = game:GetService("DataStoreService"):GetDataStore("Stroin11112")

  

XpnData = game:GetService("DataStoreService"):GetDataStore("Store212")

  

Code1Data = game:GetService("DataStoreService"):GetDataStore("Data333")

-----------------------------------------------------------------------------------

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

local LB = Instance.new("Folder", plr)

LB.Name = "leaderstats"

local debounce = Instance.new("BoolValue",plr)

debounce.Name = "debounce"

debounce.Value = Code1Data:GetAsync(plr.userId) or false

local K = Instance.new("IntValue", LB)

K.Name = "Kills"

K.Value = KillsData:GetAsync(plr.userId) or 0

  

local Xp = Instance.new ("IntValue", plr)

Xp.Name = "XP"

Xp.Value = XpData:GetAsync(plr.userId) or 0

local lvl = Instance.new ("IntValue", plr)

lvl.Name = "lvl"

lvl.Value = LvlData:GetAsync(plr.userId) or 1

local D = Instance.new("IntValue", LB)

D.Name = "Deaths"

D.Value = DeathsData:GetAsync(plr.userId) or 0

local Xpn = Instance.new("IntValue", plr)

Xpn.Name = "XpNeeded"

Xpn.Value = XpnData:GetAsync (plr.userId) or 50

Xpn.Value = 50

  

  

local r = Instance.new("IntValue", LB)

r.Name = "Rebirths"

r.Value = RebirthData:GetAsync(plr.userId) or 0

  

Xp.Changed:Connect(function()

XpData:SetAsync(plr.userId, plr.XP.Value)

end)

  

K.Changed:Connect(function()

KillsData:SetAsync(plr.userId, plr.leaderstats.Kills.Value)

end)

  

D.Changed:Connect(function()

DeathsData:SetAsync(plr.userId, plr.leaderstats.Deaths.Value)

end)

  

r.Changed:Connect(function()

RebirthData:SetAsync(plr.userId, plr.leaderstats.Rebirths.Value)

end)

  

lvl.Changed:Connect(function()

LvlData:SetAsync(plr.userId, plr.lvl.Value)

end)

  

Xpn.Changed:Connect(function()

XpnData:SetAsync(plr.userId, plr.XpNeeded.Value)

end)

  

debounce.Changed:Connect(function()

Code1Data:SetAsync(plr.userId, plr.debounce.Value)

end)

  

plr.CharacterAdded:Connect(function(char)

local humanoid

repeat

humanoid = char:FindFirstChild("Humanoid")

wait()

until humanoid

humanoid.Died:Connect(function()

D.Value = D.Value+1

local tag = humanoid:FindFirstChild("creator")

if tag then

local killer = tag.Value

if killer then

killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1

killer.XP.Value = killer.XP.Value + math.random (5,10)

  

end

end

end)

end)

end)

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

XpData:SetAsync(plr.userId, plr.XP.Value)

KillsData:SetAsync(plr.userId, plr.leaderstats.Kills.Value)

DeathsData:SetAsync(plr.userId, plr.leaderstats.Deaths.Value)

RebirthData:SetAsync(plr.userId, plr.leaderstats.Rebirths.Value)

LvlData:SetAsync(plr.userId, plr.lvl.Value)

XpnData:SetAsync(plr.userId, plr.XpNeeded.Value)

Code1Data:SetAsync(plr.userId, plr.debounce.Value)

end)`

3 comments

0

Rebirths don't save as well.

0

Seems like because you're saving everytime values are changed which isn't what you want to do. Datastores can only handle so many requests at a time. To fix your issue i'd recommend either only saving when a player leaves, or save over a period of time like every 5 minutes or so. I ran into this exact issue a couple weeks ago.

0

When I remove the .changed events it still doesn't save Xp, Xpn, Debounce, Rebirth. PS. I already have .PlayerRemoving events

1 answer

Try putting a pcall function so the script wont error and break down like this

local s,e = pcall(function()
dataname:SetAsync("key"..UserId,datahere) --change dataname,key and datahere, and maybe UserId
end)

2 comments

0

What should I change userId to?

0

the players user id

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