Created
July 30, 2021 17:01
-
-
Save RobertCodez/7ce39553883112e73454365f9051f1ab to your computer and use it in GitHub Desktop.
Stage Saver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local myData = game:GetService("DataStoreService"):GetDataStore("CodezStore") | |
game.Players.PlayerAdded:Connect(function(plr) | |
local StagesOwned = Instance.new("Folder", plr) | |
StagesOwned.Name = "StagesOwned" | |
pcall(function() | |
local data = myData:GetAsync(plr.UserId) | |
for _, v in pairs(data) do | |
local newStage = Instance.new("BoolValue", plr.StagesOwned) | |
newStage.Name = v | |
for _, object in pairs(workspace:GetChildren()) do | |
if object:FindFirstChild("Type") then | |
if object.Type.Value == v then | |
game.ReplicatedStorage.BuyStage:InvokeClient(plr, object) | |
end | |
end | |
end | |
end | |
end) | |
end) | |
game.Players.PlayerRemoving:Connect(function(plr) | |
local data = {} | |
for _,stage in pairs(plr.StagesOwned:GetChildren()) do | |
table.insert(data, stage.Name) | |
end | |
myData:SetAsync(plr.UserId, data) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment