Rest of Title: when the player leaves but loads the data back when they rejoin the game
So my tycoon format and layout is based off of GamerM8's Tycoon Series, I have tried looking at other videos of how to make a data saving datastore and modify it to try and save the tycoon I am using/made. The problem is, is that I don't know how to save and reload like droppers, walls, and stuff.
This is the buying function:
for i,v in pairs(Buttons:GetChildren()) do local NewItem = BoughtItems:FindFirstChild(v.Item.Value) if NewItem ~= nil then Items[NewItem.Name] = NewItem:Clone() NewItem:Destroy() else v.Transparency = 1 v.CanCollide = false v.ButtonPart.BillboardGui.TextLabel.Visible = false end if v:FindFirstChild("Dependency") then coroutine.resume(coroutine.create(function() v.ButtonPart.Transparency = 1 v.ButtonPart.CanCollide = false v.ButtonPart.BillboardGui.TextLabel.Visible = false if BoughtItems:WaitForChild(v.Dependency.Value, 100000) then v.ButtonPart.Transparency = 0 v.ButtonPart.BillboardGui.TextLabel.Visible = true v.ButtonPart.CanCollide = true end end)) end v.ButtonPart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(hit.Parent) if Values.OwnerValue.Value == Player then if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then if Player:WaitForChild("leaderstats").Money.Value >= v.Price.Value then Player.leaderstats.Money.Value -= v.Price.Value Items[v.Item.Value].Parent = BoughtItems v:Destroy() end end end end end) end
And this is my Data saving script (its in the same script)
local DataStoreService = game:GetServices("DataStoreService") local PlayerData = DataStoreService:GetDataStore("PlayerData") local UserOwnsTycoon = false local data = {} game.Players.PlayerAdded:Connect(function(player) UserOwnsTycoon = false while true do if player.leaderstats.OwnsTycoon == true then UserOwnsTycoon = true break end end while true do if UserOwnsTycoon == true then PlayerData:GetAsync(player.UserId) data = PlayerData:GetAsync(player.UserId, data) -- Don't know why to put here end end end) game.Players.PlayerRemoving:Connect(function(player) for i,v in pairs(BoughtItems:GetChildren()) do data = v.Name PlayerData:SetAsync(player.UserId, player.leaderstats.Money.Value, data) -- Didn't work the first time I tried end end)
Can anyone please help me? And last note, this is based off of GamerM8s Tycoon Series.
maybe change newitem to the localplayers leaderstats and make a model of the tycoon and also include that in the datastore