I made a local script where players can change those value u see down here
but when I leave (value = 1 before I leave) and join again the value = 0 (default value)
I don’t know where the problem at in my script
local DataStore = game:GetService("DataStoreService")
-- Py Game Data --
local lvlDT = DataStore:GetDataStore("lvl")
local ExpDT = DataStore:GetDataStore("Exp")
-- Py Settings Data --
local ShadowDT = DataStore:GetDataStore("Shadow")
local BloomDT = DataStore:GetDataStore("Bloom")
game.Players.PlayerAdded:Connect(function(Player)
local UserId = Player.UserId
local PyGameFolder = Instance.new("Folder",Player)
PyGameFolder.Name = "PyGameData"
local PySettingsFolder = Instance.new("Folder",Player)
PySettingsFolder.Name = "PySettingsData"
local lvl = Instance.new("IntValue",PyGameFolder)
lvl.Name = "lvl"
lvl.Value = lvlDT:GetAsync(UserId) or 1
local Exp = Instance.new("IntValue",PyGameFolder)
Exp.Name = "Exp"
Exp.Value = ExpDT:GetAsync(UserId) or 0
Exp.Changed:Connect(function()
local ExpPlus = 0
if Exp.Value >= 700*lvl.Value then
ExpPlus = Exp.Value - 700
Exp.Value = 0 + ExpPlus
lvl.Value = lvl.Value + 1
end
end)
-- Settings --
local Shadow = Instance.new("IntValue",PySettingsFolder)
Shadow.Name = "Shadow"
Shadow.Value = ShadowDT:GetAsync(UserId) or 0
local Bloom = Instance.new("IntValue",PySettingsFolder)
Bloom.Name = "Bloom"
Bloom.Value = BloomDT:GetAsync(UserId) or 0
end)
game.Players.PlayerRemoving:Connect(function(Player)
local UserId = Player.UserId
local PyGameFolder = Player:WaitForChild("PyGameData")
local PySettingsFolder = Player:WaitForChild("PySettingsData")
local lvl = PyGameFolder:WaitForChild("lvl")
local Exp = PyGameFolder:WaitForChild("Exp")
local Shadow = PySettingsFolder:WaitForChild("Shadow")
local Bloom = PySettingsFolder:WaitForChild("Bloom")
lvlDT:SetAsync(UserId, lvl.Value)
ExpDT:SetAsync(UserId, Exp.Value)
ShadowDT:SetAsync(UserId, Shadow.Value)
BloomDT:SetAsync(UserId, Bloom.Value)
end)