Hello there! I am have a DataStore and everything worked fine, but now suddenly it only loads data, but it will not save.
-
What do you want to achieve? Keep it simple and clear!
I want to create a DataStore that saves all the data from the player -
What is the issue? Include screenshots / videos if possible!
There are no errors in output, but the data will not ‘rewrite’ -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked on the Developer Hub, but I didn’t found someone with the same problem as me
The script in ServerScriptService:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(player)
local PlayerStats = Instance.new("Folder")
PlayerStats.Name = "Stats"
PlayerStats.Parent = player
local WalkSpeed = Instance.new("IntValue")
WalkSpeed.Name = "WalkSpeed"
WalkSpeed.Parent = PlayerStats
WalkSpeed.Value = 16
local RunSpeed = Instance.new("IntValue")
RunSpeed.Name = "RunSpeed"
RunSpeed.Parent = PlayerStats
RunSpeed.Value = 30
local JumpCooldown = Instance.new("IntValue")
JumpCooldown.Name = "Cooldown"
JumpCooldown.Parent = PlayerStats
JumpCooldown.Value = 2
local JumpPower = Instance.new("IntValue")
JumpPower.Name = "JumpPower"
JumpPower.Parent = PlayerStats
JumpPower.Value = 50
local Health = Instance.new("IntValue")
Health.Name = "Health"
Health.Parent = PlayerStats
Health.Value = 200
local Melee = Instance.new("IntValue")
Melee.Name = "Melee"
Melee.Parent = PlayerStats
Melee.Value = 60
local Vision = Instance.new("IntValue")
Vision.Name = "Vision"
Vision.Parent = PlayerStats
Vision.Value = 70
local Reload = Instance.new("NumberValue")
Reload.Name = "Reload"
Reload.Parent = PlayerStats
Reload.Value = 1
local Grenades = Instance.new("IntValue")
Grenades.Name = "SpawnGrenades"
Grenades.Parent = PlayerStats
Grenades.Value = 2
local GrenadeAmount = Instance.new("IntValue")
Grenades.Name = "Grenades"
Grenades.Parent = PlayerStats
Grenades.Value = 2
local Name = Instance.new("StringValue")
Name.Name = "Character"
Name.Parent = PlayerStats
Name.Value = player.Name
local Playing = Instance.new("BoolValue")
Playing.Name = "Playing"
Playing.Parent = player
Playing.Value = false
local Voted = Instance.new("BoolValue")
Voted.Parent = player
Voted.Name = "Voted"
local Jumpscare = Instance.new("BoolValue")
Jumpscare.Parent = PlayerStats
Jumpscare.Name = "Jumpscare"
local InGame = Instance.new("BoolValue")
InGame.Parent = player
InGame.Name = "InGame"
local WaitingFeedback = Instance.new("BoolValue")
WaitingFeedback.Parent = player
WaitingFeedback.Name = "WaitingFeedback"
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = player
Money.Value = 500
local SelectedPrimary = Instance.new("StringValue")
SelectedPrimary.Name = "SelectedPrimary"
SelectedPrimary.Parent = PlayerStats
SelectedPrimary.Value = "AK74M"
local SelectedSecundary = Instance.new("StringValue")
SelectedSecundary.Name = "SelectedSecundary"
SelectedSecundary.Parent = PlayerStats
SelectedSecundary.Value = "AKS74U"
local SelectedMelee = Instance.new("StringValue")
SelectedMelee.Name = "SelectedMelee"
SelectedMelee.Parent = PlayerStats
SelectedMelee.Value = "Machete"
local SelectedExtra = Instance.new("StringValue")
SelectedExtra.Name = "SelectedExtra"
SelectedExtra.Parent = PlayerStats
SelectedExtra.Value = "Binoculars"
local CakeKniveSkin = Instance.new("StringValue")
CakeKniveSkin.Name = "CakeKniveSkin"
CakeKniveSkin.Parent = PlayerStats
local PrimarySkin = Instance.new("StringValue")
PrimarySkin.Name = "PrimarySkin"
PrimarySkin.Parent = PlayerStats
local SecundarySkin = Instance.new("StringValue")
SecundarySkin.Name = "SecundarySkin"
SecundarySkin.Parent = PlayerStats
--[[local Skins = Instance.new("Folder")
Skins.Parent = player
Skins.Name = "Skins"
local Water = Instance.new("BoolValue")
Water.Name = "Water"
Water.Parent = Skins
local Lava = Instance.new("BoolValue")
Lava.Name = "Lava"
Lava.Parent = Skins
local Couch = Instance.new("BoolValue")
Couch.Name = "Couch"
Couch.Parent = Skins
local Foil = Instance.new("BoolValue")
Foil.Name = "Foil"
Foil.Parent = Skins
local Wood = Instance.new("BoolValue")
Wood.Name = "Wood"
Wood.Parent = Skins
local Marble = Instance.new("BoolValue")
Marble.Name = "Marble"
Marble.Parent = Skins
local Fur = Instance.new("BoolValue")
Fur.Name = "Fur"
Fur.Parent = Skins
local Rocks = Instance.new("BoolValue")
Rocks.Name = "Rocks"
Rocks.Parent = Skins
local Platinum = Instance.new("BoolValue")
Platinum.Name = "Platinum"
Platinum.Parent = Skins
local Diamond = Instance.new("BoolValue")
Diamond.Name = "Diamond"
Diamond.Parent = Skins
local Gold = Instance.new("BoolValue")
Gold.Name = "Gold"
Gold.Parent = Skins
local Loadouts = Instance.new("Folder")
Loadouts.Name = "Loadouts"
Loadouts.Parent = player
local Loadout1 = Instance.new("Folder")
Loadout1.Name = "Loadout1"
Loadout1.Parent = Loadouts
local Loadout1Primary = Instance.new("StringValue")
Loadout1Primary.Name = "Primary"
Loadout1Primary.Parent = Loadout1
local Loadout1Secundary = Instance.new("StringValue")
Loadout1Secundary.Name = "Secundary"
Loadout1Secundary.Parent = Loadout1
local Loadout1Melee = Instance.new("StringValue")
Loadout1Melee.Name = "Melee"
Loadout1Melee.Parent = Loadout1
local Loadout1Extra = Instance.new("StringValue")
Loadout1Extra.Name = "Extra"
Loadout1Extra.Parent = Loadout1
local Loadout1Name = Instance.new("StringValue")
Loadout1Name.Name = "Name"
Loadout1Name.Parent = Loadout1
local Loadout2 = Instance.new("Folder")
Loadout2.Name = "Loadout2"
Loadout2.Parent = Loadouts
local Loadout2Primary = Instance.new("StringValue")
Loadout2Primary.Name = "Primary"
Loadout2Primary.Parent = Loadout2
local Loadout2Secundary = Instance.new("StringValue")
Loadout2Secundary.Name = "Secundary"
Loadout2Secundary.Parent = Loadout2
local Loadout2Melee = Instance.new("StringValue")
Loadout2Melee.Name = "Melee"
Loadout2Melee.Parent = Loadout2
local Loadout2Extra = Instance.new("StringValue")
Loadout2Extra.Name = "Extra"
Loadout2Extra.Parent = Loadout2
local Loadout2Name = Instance.new("StringValue")
Loadout2Name.Name = "Name"
Loadout2Name.Parent = Loadout2
local Loadout3 = Instance.new("Folder")
Loadout3.Name = "Loadout2"
Loadout3.Parent = Loadouts
local Loadout3Primary = Instance.new("StringValue")
Loadout3Primary.Name = "Primary"
Loadout3Primary.Parent = Loadout3
local Loadout3Secundary = Instance.new("StringValue")
Loadout3Secundary.Name = "Secundary"
Loadout3Secundary.Parent = Loadout3
local Loadout3Melee = Instance.new("StringValue")
Loadout3Melee.Name = "Melee"
Loadout3Melee.Parent = Loadout3
local Loadout3Extra = Instance.new("StringValue")
Loadout3Extra.Name = "Extra"
Loadout3Extra.Parent = Loadout3
local Loadout3Name = Instance.new("StringValue")
Loadout3Name.Name = "Name"
Loadout3Name.Parent = Loadout3]]--
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = player
local Deaths = Instance.new("IntValue")
Deaths.Name = "Deaths"
Deaths.Parent = player
local KD = Instance.new("IntValue")
KD.Name = "KD"
KD.Parent = player
local RoundKills = Instance.new("IntValue")
RoundKills.Name = "RoundKills"
RoundKills.Parent = PlayerStats
local RoundDeaths = Instance.new("IntValue")
RoundDeaths.Name = "RoundDeaths"
RoundDeaths.Parent = PlayerStats
local RoundKD = Instance.new("StringValue")
RoundKD.Name = "RoundKD"
RoundKD.Parent = PlayerStats
local Matches = Instance.new("IntValue")
Matches.Name = "Matches"
Matches.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = player
local TeamName = Instance.new("StringValue")
TeamName.Name = "TeamName"
TeamName.Parent = PlayerStats
local TeamColor = Instance.new("Color3Value")
TeamColor.Name = "TeamColor"
TeamColor.Parent = PlayerStats
local Settings = Instance.new("Folder")
Settings.Name = "Settings"
Settings.Parent = player
local Crosshair = Instance.new("BoolValue")
Crosshair.Name = "Crosshair"
Crosshair.Parent = Settings
Crosshair.Value = true
local CrosshairColor = Instance.new("Color3Value")
CrosshairColor.Name = "CrosshairColor"
CrosshairColor.Parent = Settings
CrosshairColor.Value = Color3.new(1, 1, 1)
local VictoryMusic = Instance.new("BoolValue")
VictoryMusic.Name = "VictoryMusic"
VictoryMusic.Parent = Settings
VictoryMusic.Value = true
local LobbyMusic = Instance.new("BoolValue")
LobbyMusic.Name = "LobbyMusic"
LobbyMusic.Parent = Settings
LobbyMusic.Value = true
local HealthGui = Instance.new("BoolValue")
HealthGui.Name = "HealthGui"
HealthGui.Parent = Settings
HealthGui.Value = true
local KillGui = Instance.new("BoolValue")
KillGui.Name = "KillGui"
KillGui.Parent = Settings
KillGui.Value = true
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = player
Level.Value = 1
local Exp = Instance.new("IntValue")
Exp.Parent = Level
Exp.Name = "Current"
Exp.Value = 0
local MaxExp = Instance.new("IntValue")
MaxExp.Parent = Level
MaxExp.Name = "Max"
MaxExp.Value = 100
local KillExp = Instance.new("IntValue")
KillExp.Parent = PlayerStats
KillExp.Name = "KillExp"
local ChallengeExp = Instance.new("IntValue")
ChallengeExp.Parent = PlayerStats
ChallengeExp.Name = "ChallengeExp"
local Challenges = Instance.new("Folder")
Challenges.Name = "Challenges"
Challenges.Parent = player
local Week1 = Instance.new("Folder")
Week1.Name = "Week1"
Week1.Parent = Challenges
local Challenge1 = Instance.new("BoolValue")
Challenge1.Name = "Round20Kills"
Challenge1.Parent = Week1
local Challenge2 = Instance.new("BoolValue")
Challenge2.Name = "Win"
Challenge2.Parent = Week1
local Challenge3 = Instance.new("BoolValue")
Challenge3.Name = "WinWithoutDeath"
Challenge3.Parent = Week1
local Challenge4 = Instance.new("BoolValue")
Challenge4.Name = "KDAbove2"
Challenge4.Parent = Week1
local Challenge5 = Instance.new("BoolValue")
Challenge5.Name = "Total100Kills"
Challenge5.Parent = Week1
local Week2 = Instance.new("Folder")
Week2.Name = "Week2"
Week2.Parent = Challenges
local Challenge6 = Instance.new("BoolValue")
Challenge6.Name = "Studs100"
Challenge6.Parent = Week2
local Challenge7 = Instance.new("BoolValue")
Challenge7.Name = "MeleeKill"
Challenge7.Parent = Week2
local Challenge8 = Instance.new("BoolValue")
Challenge8.Name = "AbandonedWin"
Challenge8.Parent = Week2
local Challenge9 = Instance.new("BoolValue")
Challenge9.Name = "WeaponSwapWin"
Challenge9.Parent = Week2
local Challenge10 = Instance.new("BoolValue")
Challenge10.Name = "LaserTagWin"
Challenge10.Parent = Week2
local Week3 = Instance.new("Folder")
Week3.Name = "Week3"
Week3.Parent = Challenges
local Challenge11 = Instance.new("BoolValue")
Challenge11.Name = "InaRoyaleWin"
Challenge11.Parent = Week3
local Challenge12 = Instance.new("BoolValue")
Challenge12.Name = "HenkeMacheteKill"
Challenge12.Parent = Week3
local Challenge13 = Instance.new("BoolValue")
Challenge13.Name = "MischaCakeKniveKill"
Challenge13.Parent = Week3
local Challenge14 = Instance.new("BoolValue")
Challenge14.Name = "BananaKill"
Challenge14.Parent = Week3
local Challenge15 = Instance.new("BoolValue")
Challenge15.Name = "KS4A4CarbineKill"
Challenge15.Parent = Week3
local data
local success, errorMsg = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
if data ~= nil then
if data.Wins then
Wins.Value = data.Wins
end
if data.Matches then
Matches.Value = data.Matches
end
if data.Kills then
Kills.Value = data.Kills
end
--if data.Deaths then
--Deaths.Value = data.Deaths
--end
if data.Level then
Level.Value = data.Level
end
if data.CurrentExp then
Exp.Value = data.CurrentExp
end
if data.Character then
Name.Value = data.Character
end
if data.JumpPower then
JumpPower.Value = data.JumpPower
end
if data.Health then
Health.Value = data.Health
end
if data.JumpCooldown then
JumpCooldown = data.JumpCooldown
end
if data.Melee then
Melee.Value = data.Melee
end
if data.RunSpeed then
RunSpeed.Value = data.RunSpeed
end
if data.WalkSpeed then
WalkSpeed.Value = data.WalkSpeed
end
if data.SelectedExtra then
SelectedExtra.Value = data.SelectedExtra
end
if data.SelectedMelee then
SelectedMelee.Value = data.SelectedMelee
end
if data.SelectedPrimary then
SelectedPrimary.Value = data.SelectedPrimary
end
if data.SelectedSecundary then
SelectedSecundary.Value = data.SelectedSecundary
end
if data.CakeKniveSkin then
CakeKniveSkin.Value = data.CakeKniveSkin
end
if data.Crosshair then
Crosshair.Value = data.Crosshair
end
if data.CrosshairColor then
CrosshairColor.Value = data.CrosshairColor
end
if data.VictoryMusic then
VictoryMusic.Value = data.VictoryMusic
end
if data.LobbyMusic then
LobbyMusic.Value = data.LobbyMusic
end
if data.HealthGui then
HealthGui.Value = data.HealthGui
end
if data.KillGui then
KillGui.Value = data.KillGui
end
if data.Challenge1 then
Challenge1.Value = data.Challenge1
end
if data.Challenge2 then
Challenge2.Value = data.Challenge2
end
if data.Challenge3 then
Challenge3.Value = data.Challenge3
end
if data.Challenge4 then
Challenge4.Value = data.Challenge4
end
if data.Challenge5 then
Challenge5.Value = data.Challenge5
end
if data.Challenge6 then
Challenge6.Value = data.Challenge6
end
if data.Challenge7 then
Challenge7.Value = data.Challenge7
end
if data.Challenge8 then
Challenge8.Value = data.Challenge8
end
if data.Challenge9 then
Challenge9.Value = data.Challenge9
end
if data.Challenge10 then
Challenge10.Value = data.Challenge10
end
if data.Challenge11 then
Challenge11.Value = data.Challenge11
end
if data.Challenge12 then
Challenge12.Value = data.Challenge12
end
if data.Challenge13 then
Challenge13.Value = data.Challenge13
end
if data.Challenge14 then
Challenge14.Value = data.Challenge14
end
if data.Challenge15 then
Challenge15.Value = data.Challenge15
end
if data.Deaths then
Deaths.Value = data.Deaths
end
if data.Crosshair then
Crosshair.Value = data.Crosshair
end
if data.CrosshairColor then
CrosshairColor.Value = data.CrosshairColor
end
if data.VictoryMusic then
VictoryMusic.Value = data.VictoryMusic
end
if data.LobbyMusic then
LobbyMusic.Value = data.LobbyMusic
end
if data.HealthGui then
HealthGui.Value = data.HealthGui
end
if data.KillGui then
KillGui.Value = data.KillGui
end
end
repeat wait()
until game.Players:FindFirstChild(player.Name)
local HeadLight = Instance.new("SpotLight")
HeadLight.Parent = game.Players:FindFirstChild(player.Name).Character:FindFirstChild("Head")
HeadLight.Angle = 99
HeadLight.Brightness = 4
HeadLight.Range = 33
HeadLight.Face = "Front"
HeadLight.Enabled = false
HeadLight.Name = "HeadLight"
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {}
data.Wins = player.Wins.Value
data.Matches = player.Matches.Value
data.Kills = player.Kills.Value
data.Deaths = player.Deaths.Value
data.Level = player.Level.Value
data.CurrentExp = player.Level.Current.Value
data.Character = player.Stats.Character.Value
data.JumpPower = player.Stats.JumpPower.Value
--data.Grenades = player.Stats.Grenades.Value
data.Health = player.Stats.Health.Value
data.JumpCooldown = player.Stats.Cooldown.Value
data.Melee = player.Stats.Melee.Value
--data.Reload = player.Stats.Reload.Value
data.RunSpeed = player.Stats.RunSpeed.Value
--data.SpawnGrenades = player.Stats.SpawnGrenades.Value
--data.Vision = player.Stats.Vision.Value
data.WalkSpeed = player.Stats.WalkSpeed.Value
data.SelectedExtra = player.Stats.SelectedExtra.Value
data.SelectedMelee = player.Stats.SelectedMelee.Value
data.SelectedPrimary = player.Stats.SelectedPrimary.Value
data.SelectedSecundary = player.Stats.SelectedSecundary.Value
data.CakeKniveSkin = player.Stats.CakeKniveSkin
data.Crosshair = player.Settings.Crosshair.Value
data.CrosshairColor = player.Settings.CrosshairColor.Value
data.VictoryMusic = player.Settings.VictoryMusic.Value
data.LobbyMusic = player.Settings.LobbyMusic.Value
data.HealthGui = player.Settings.HealthGui.Value
data.KillGui = player.Settings.KillGui.Value
data.Challenge1 = player.Challenges.Week1.Round20Kills.Value
data.Challenge2 = player.Challenges.Week1.Win.Value
data.Challenge3 = player.Challenges.Week1.WinWithoutDeath.Value
data.Challenge4 = player.Challenges.Week1.KDAbove2.Value
data.Challenge5 = player.Challenges.Week1.Total100Kills.Value
data.Challenge6 = player.Challenges.Week2.Studs100.Value
data.Challenge7 = player.Challenges.Week2.MeleeKill.Value
data.Challenge8 = player.Challenges.Week2.AbandonedWin.Value
data.Challenge9 = player.Challenges.Week2.WeaponSwapWin.Value
data.Challenge10 = player.Challenges.Week2.LaserTagWin.Value
data.Challenge11 = player.Challenges.Week3.InaRoyaleWin.Value
data.Challenge12 = player.Challenges.Week3.HenkeMacheteKill.Value
data.Challenge13 = player.Challenges.Week3.MischaCakeKniveKill.Value
data.Challenge14 = player.Challenges.Week3.BananaKill.Value
data.Challenge15 = player.Challenges.Week3.KS4A4CarbineKill.Value
local success,errorMsg = pcall(function()
DataStore:SetAsync(player.UserId,data)
end)
if success then
print("Succesfully saved")
end
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
local data = {}
data.Wins = player.Wins.Value
data.Matches = player.Matches.Value
data.Kills = player.Kills.Value
data.Deaths = player.Deaths.Value
data.Level = player.Level.Value
data.CurrentExp = player.Level.Current.Value
data.Character = player.Stats.Character.Value
data.JumpPower = player.Stats.JumpPower.Value
--data.Grenades = player.Stats.Grenades.Value
data.Health = player.Stats.Health.Value
data.JumpCooldown = player.Stats.Cooldown.Value
data.Melee = player.Stats.Melee.Value
--data.Reload = player.Stats.Reload.Value
data.RunSpeed = player.Stats.RunSpeed.Value
--data.SpawnGrenades = player.Stats.SpawnGrenades.Value
--data.Vision = player.Stats.Vision.Value
data.WalkSpeed = player.Stats.WalkSpeed.Value
data.SelectedExtra = player.Stats.SelectedExtra.Value
data.SelectedMelee = player.Stats.SelectedMelee.Value
data.SelectedPrimary = player.Stats.SelectedPrimary.Value
data.SelectedSecundary = player.Stats.SelectedSecundary.Value
data.CakeKniveSkin = player.Stats.CakeKniveSkin
data.Crosshair = player.Settings.Crosshair.Value
data.CrosshairColor = player.Settings.CrosshairColor.Value
data.VictoryMusic = player.Settings.VictoryMusic.Value
data.LobbyMusic = player.Settings.LobbyMusic.Value
data.HealthGui = player.Settings.HealthGui.Value
data.KillGui = player.Settings.KillGui.Value
data.Challenge1 = player.Challenges.Week1.Round20Kills.Value
data.Challenge2 = player.Challenges.Week1.Win.Value
data.Challenge3 = player.Challenges.Week1.WinWithoutDeath.Value
data.Challenge4 = player.Challenges.Week1.KDAbove2.Value
data.Challenge5 = player.Challenges.Week1.Total100Kills.Value
data.Challenge6 = player.Challenges.Week2.Studs100.Value
data.Challenge7 = player.Challenges.Week2.MeleeKill.Value
data.Challenge8 = player.Challenges.Week2.AbandonedWin.Value
data.Challenge9 = player.Challenges.Week2.WeaponSwapWin.Value
data.Challenge10 = player.Challenges.Week2.LaserTagWin.Value
data.Challenge11 = player.Challenges.Week3.InaRoyaleWin.Value
data.Challenge12 = player.Challenges.Week3.HenkeMacheteKill.Value
data.Challenge13 = player.Challenges.Week3.MischaCakeKniveKill.Value
data.Challenge14 = player.Challenges.Week3.BananaKill.Value
data.Challenge15 = player.Challenges.Week3.KS4A4CarbineKill.Value
local success,errorMsg = pcall(function()
DataStore:SetAsync(player.UserId,data)
end)
if success then
print("Succesfully saved")
end
end
end)