so i was making a settings system and leaderstats .
**What is the issue?
idk why but all the values keep changing back to 0 even i write how much value i want in the script .
Here’s the script below
local DataStoreService = game:GetService("DataStoreService")
--Get myDataStore
local myDataStore = DataStoreService:GetDataStore("FifthOfUsDataStore")
--Satisfy Scripting
game.Players.PlayerAdded:Connect(function(player)
--Leaderstats Folder
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
--Settings Folder
local Options = Instance.new("Folder")
Options.Name = "Settings"
Options.Parent = player
--Cash
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
Cash.Value = 100
--ChosenCharacter
local Char = Instance.new("IntValue")
Char.Name = "Char"
Char.Parent = leaderstats
Char.Value = 3
--Flashlight 1 = LMB 2 = RMB 3 = F
local Flashlight = Instance.new("IntValue")
Flashlight.Name = "Flashlight"
Flashlight.Parent = Options
Flashlight.Value = 2
--Phone Control
local PhoneControl = Instance.new("BoolValue")
PhoneControl.Name = "PhoneControl"
PhoneControl.Parent = Options
--Shadows Softness
local ShadowSoftness = Instance.new("BoolValue")
ShadowSoftness.Name = "ShadowSoftness"
ShadowSoftness.Parent = Options
--Shadows
local Shadows = Instance.new("BoolValue")
Shadows.Name = "Shadows"
Shadows.Parent = Options
--FPS
local ShowFPS = Instance.new("BoolValue")
ShowFPS.Name = "ShowFPS"
ShowFPS.Parent = Options
--Ping
local ShowPing = Instance.new("BoolValue")
ShowPing.Name = "ShowPing"
ShowPing.Parent = Options
local data
local success, errormessage = pcall(function()
--Values Data
data = myDataStore:GetAsync(player.UserId.."-Char")
data = myDataStore:GetAsync(player.UserId.."-Flashlight")
data = myDataStore:GetAsync(player.UserId.."-Cash")
data = myDataStore:GetAsync(player.UserId.."-Flashlight")
data = myDataStore:GetAsync(player.UserId.."-PhoneControl")
data = myDataStore:GetAsync(player.UserId.."-ShadowSoftness")
data = myDataStore:GetAsync(player.UserId.."-Shadows")
data = myDataStore:GetAsync(player.UserId.."-ShowFPS")
data = myDataStore:GetAsync(player.UserId.."-ShowPing")
end)
if success then
--Values Data
Char.Value = data
Flashlight.Value = data
Cash.Value = data
PhoneControl.Value = data
ShadowSoftness.Value = data
Shadows.Value = data
ShowFPS.Value = data
ShowPing.Value = data
else
print("There is an error , Caution !")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
--Values Data
myDataStore:SetAsync(player.UserId.."-Char", player.leaderstats.Char.Value)
myDataStore:SetAsync(player.UserId.."-Flashlight", player.Settings.Flashlight.Value)
myDataStore:SetAsync(player.UserId.."-Cash", player.leaderstats.Cash.Value)
myDataStore:SetAsync(player.UserId.."-PhoneControl", player.Settings.PhoneControl.Value)
myDataStore:SetAsync(player.UserId.."-ShadowSoftness", player.Settings.ShadowSoftness.Value)
myDataStore:SetAsync(player.UserId.."-Shadows", player.Settings.Shadows.Value)
myDataStore:SetAsync(player.UserId.."-ShowFPS", player.Settings.ShowFPS.Value)
myDataStore:SetAsync(player.UserId.."-ShowPing", player.Settings.ShowPing.Value)
end)
if success then
print("Player Data Successfully Saved !")
else
print("There is an error , Caution !")
warn(errormessage)
end
end)
--pls tell me why my leaderstats and other folder's value keep changing the value to 0 . Thanks !
IntValue.Value = Data1 or 20 -- set the "20" into your default value, and set the "data" variable into different variables like "data1", "data2" or else it will return in a same result
and to save data use :SetAsync() or either :UpdateAsync() to update the datasaved value
local data
local success, errormessage = pcall(function()
--Values Data
data = myDataStore:GetAsync(player.UserId)
end)
if success and data then
--Values Data
Char.Value = data.Char
Flashlight.Value = data.Flashlight
Cash.Value = data.Cash
PhoneControl.Value = data.PhoneControl
ShadowSoftness.Value = data.ShadowSoftness
Shadows.Value = data.Shadows
ShowFPS.Value = data.ShowFPS
ShowPing.Value = data.ShowPing
else
print("There is an error , Caution !")
warn(errormessage)
end
end)