-
What i want to do?
I am making a saving tycoon (is a original tycoon) but when i try to load player’s data, work, but all tycoon buttons destroy
local function LoadTycoon()
local Done = false
for i,tycoon in pairs(game.Workspace.Tycoons:GetChildren()) do
local Owner = tycoon.Configuration.Owner
if Owner.Value == plr.Name and Done == false then
Done = true
wait(7)--To load plr's data
local ItemsStats = plr:WaitForChild("ExtraStats",10).Items
if ItemsStats.Value == "" then
print("New user!")
else
print("Loading saved tycoon")
local values = ItemsStats.Value:split(",")
for i=1,#values do
print(values[i])
for i,v in pairs(ItemsFolder:GetChildren()) do
if v.Name == values[i] then
for i2,Item in pairs(tycoon.Items:GetChildren()) do
v.Item:Clone().Parent = Item
if Item:FindFirstChild("Button") then
Item:FindFirstChild("Button"):Destroy()
end
print("Item loaded")
end
end
end
end
end
end
end
end
LoadTycoon()
Why it delete all buttons?
(I am learning yet, so pls tell me if there is a better way to make it)
btw i use DataStore2
ItemsFolder is a folder is server storage