How can I create a datastore that saves a players progress-?
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:
01 | for i,v in pairs (Buttons:GetChildren()) do |
02 | local NewItem = BoughtItems:FindFirstChild(v.Item.Value) |
03 | if NewItem ~ = nil then |
04 | Items [ NewItem.Name ] = NewItem:Clone() |
10 | v.ButtonPart.BillboardGui.TextLabel.Visible = false |
13 | if v:FindFirstChild( "Dependency" ) then |
14 | coroutine.resume(coroutine.create( function () |
15 | v.ButtonPart.Transparency = 1 |
16 | v.ButtonPart.CanCollide = false |
17 | v.ButtonPart.BillboardGui.TextLabel.Visible = false |
18 | if BoughtItems:WaitForChild(v.Dependency.Value, 100000 ) then |
19 | v.ButtonPart.Transparency = 0 |
20 | v.ButtonPart.BillboardGui.TextLabel.Visible = true |
21 | v.ButtonPart.CanCollide = true |
25 | v.ButtonPart.Touched:Connect( function (hit) |
26 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
27 | local Player = game.Players:GetPlayerFromCharacter(hit.Parent) |
28 | if Values.OwnerValue.Value = = Player then |
29 | if v.ButtonPart.CanCollide = = true and v.ButtonPart.Transparency = = 0 then |
30 | if Player:WaitForChild( "leaderstats" ).Money.Value > = v.Price.Value then |
31 | Player.leaderstats.Money.Value - = v.Price.Value |
32 | Items [ v.Item.Value ] .Parent = BoughtItems |
And this is my Data saving script (its in the same script)
01 | local DataStoreService = game:GetServices( "DataStoreService" ) |
03 | local PlayerData = DataStoreService:GetDataStore( "PlayerData" ) |
04 | local UserOwnsTycoon = false |
07 | game.Players.PlayerAdded:Connect( function (player) |
08 | UserOwnsTycoon = false |
10 | if player.leaderstats.OwnsTycoon = = true then |
16 | if UserOwnsTycoon = = true then |
17 | PlayerData:GetAsync(player.UserId) |
18 | data = PlayerData:GetAsync(player.UserId, data) |
26 | game.Players.PlayerRemoving:Connect( function (player) |
27 | for i,v in pairs (BoughtItems:GetChildren()) do |
29 | PlayerData:SetAsync(player.UserId, player.leaderstats.Money.Value, data) |
This is what the model layout looks like, and the items in "BoughtItems" are not there until you buy them
Can anyone please help me? And last note, this is based off of GamerM8s Tycoon Series.