I have gotten a script I made in a previous game and I’m trying to make it save boolean values, I’m not quite sure if that’s the main problem but here’s my current script, please tell me if you find anything wrong:
local dataStoreService = game:GetService("DataStoreService")
local PassivesDataStore = dataStoreService:GetGlobalDataStore("PassiveValues")
local loaded = {}
game.Players.PlayerAdded:Connect(function(player)
local Passives = player:WaitForChild("Passives")
if player.UserId > 0 and player.Parent then
local PassivesData = PassivesDataStore:GetAsync(player.UserId)
if PassivesData ~= "Request Rejected" then
if PassivesData then
for i, stat in ipairs(Passives:GetChildren()) do
local value = PassivesData[stat.Name]
if value then
stat.Value = value
end
end
end
loaded[player] = true
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Passives = player:FindFirstChild("Passives")
if Passives then
print("foundpassives")
if loaded[player] then
local PassivesData = {}
for i, stat in ipairs(Passives:GetChildren()) do
PassivesData[stat.Name] = stat.Value
end
PassivesDataStore:SetAsync(player.UserId, PassivesData)
end
end
loaded[player] = nil
end)