So basically, I have a folder called Owned, and everything in their are BoolValues but the thing is it only clones when it checks you have it owned, so I wanna make it check the saved table of what you bought (Inside of Suphi’s Datastore Table) and clone to bool value into the Owned folder.
-- Player DataStore Script
local DataStoreModule = require(11671168253)
local template = {
Owned = {},
}
local function StateChanged(state, dataStore)
while dataStore.State == false do
if dataStore:Open(template) ~= "Success" then task.wait(6) end
end
end
game.Players.PlayerAdded:Connect(function(player)
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.StateChanged:Connect(StateChanged)
StateChanged(dataStore.State, dataStore)
end)
game.Players.PlayerRemoving:Connect(function(player)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore ~= nil then dataStore:Destroy() end
end)
-- Owned Module
local module = {}
local DataStoreModule = require(11671168253)
local function StateChanged(state, dataStore)
if dataStore.State ~= true then return end
dataStore.OwnedFolder:ClearAllChildren()
for id, value in dataStore.Value.Owned do
local boolValue = instance.new("BoolValue")
boolValue.Name = id
boolValue.Value = true
boolValue.Parent = dataStore.OwnedFolder
end
end
game.Players.PlayerAdded:Connect(function(player)
local ownedFolder = instance.new("Folder")
ownedFolder.Parent = player
local dataStore = DataStoreModule.new("Player", player.UserId)
dataStore.OwnedFolder = ownedFolder
dataStore.StateChanged:Connect(StateChanged)
end)
function module.SetOwned(player, id, owned)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore == nil then return false end
if dataStore.State ~= true then return false end
if owned then
if dataStore.Value.Owned[id] == true then return true end
dataStore.Value.Owned[id] == true
local boolValue = instance.new("BoolValue")
boolValue.Name = id
boolValue.Value = true
boolValue.Parent = dataStore.OwnedFolder
else
if dataStore.Value.Owned[id] == nil then return true end
dataStore.Value.Owned[id] == nil
dataStore.OwnedFolder[id]:Destroy()
end
return true
end
function module.IsOwned(player, id)
local dataStore = DataStoreModule.find("Player", player.UserId)
if dataStore == nil then return end
if dataStore.State ~= true then return end
return dataStore.Value.Owned[id] ~= nil
end
return module
-- Random Script
local OwnedModule = require(PathToOwnedModule)
local success = OwnedModule.SetOwned(SomePlayer, "House1", true)
if success == false then error("Failed to set ownership") end
local owned1 = OwnedModule.IsOwned(SomePlayer, "House1",)
if owned1 == nil then error("Failed to get ownership") end
print(owned1)
local owned2 = OwnedModule.IsOwned(SomePlayer, "House2",)
if owned2 == nil then error("Failed to get ownership") end
print(owned2)