Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can we make the script save forever?

Asked by 4 years ago

How do we make a script save for every time for example: Just like in tycoon we get money we upgrade and when we leave the server and join back later. we want the tycoon to be saved. we don't want to restart again we want to have our data saved. But i don't really understand how to do so can someone explain how we can make a save script that saves things when we join a new server.

0
This requires DataStoreService, why not a BoolValue that turns true for every stage you buy? For example, when the player touches a button. The script from that button turns the BoolValue into true so when they left, the server will check the BoolValues and their progress is saved. cherrythetree 130 — 4y
0
ok thanks i will check it. mastercheeseit 77 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

It saves a script to the stringvalue, so it saves script forever.

1local SaveScriptForever = Instance.new("StringValue")
2SaveScriptForever.Name = "SaveScriptForever"
3SaveScriptForever.Value = "a"
4SaveScriptForever.Parent = game.ServerStorage
5    scriptpathyouwanttosaveforever.Source = SaveScriptForever.Value
Ad
Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You will have to use DataStoreService, it saves the data to the cloud.

Here is a little example of how to save data into the data store, i haven't tested it but what it does is that it takes all values from a specific folder (that you can select) and gets their names and then saves them into a table. Whenever a player joins, you should create a folder for him and whenever he buys a structure, create instance which will have the structure's name and put it into the folder (no matter what instance). Then when he joins back it should return the table with saved structure's strings and all you have to do then is just to check if player has the structure by it's name. Again i haven't tested it but if you will have any errors there you can ask.

01local DataStoreService = game:GetService("DataStoreService")
02local Players = game:GetService("Players")
03 
04local DataStore = DataStoreService:GetDataStore("YOUR_DATA_STORE_NAME")
05 
06local function SaveData(Player)
07    if Player then
08 
09        local OwnedStructuresFolder = Player:FindFirstChild("OwnedStructuresFolder") -- Finds the structures folder
10 
11        if OwnedStructuresFolder then
12            local OwnedStructuresToSave = {} -- Table in which we will save the strings
13 
14            for _, OwnedStructure in pairs(OwnedStructuresFolder:GetChildren()) do  -- For every single value in the folder do (_ is variable for index but we won't need it)
15 
View all 50 lines...
Log in to vote
0
Answered by 4 years ago

Hey! By what you are saying, you need to learn about the DataStoreService. Also, you will need to know how to make a leaderboard, and if you dont, you should learn that. Here is an example script, put this in ServerScriptService

01-- Services
02local Players = game.Players
03local DataStoreService = game:GetService("DataStoreService")
04 
05-- Data Store
06local PlayerData = DataStoreService:GetDataStore("PlayerData")
07 
08Players.PlayerAdded:Connect(function(Player)
09    -- Leaderboard (Dont change this)
10    local leaderstats = Instance.new("Folder")
11    leaderstats.Name = "leaderstats"
12    leaderstats.Parent = Player
13 
14    -- Cash
15    local Cash = Instance.new("IntValue")
View all 40 lines...

To test this, just try and change the players cash in-game, and leave, then join back in. If you need help with this, put the following code in a script with its parent being a part, and touch the part

01local Part = script.Parent
02local debounce = false
03 
04Part.Touched:Connect(function(hit)
05    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
06    if Player then
07        debounce = true
08        local Cash = Player.leaderstats.Cash
09        Cash.Value = Cash.Value+10 -- Change this to whatever
10        Part.TouchEnded:Wait()
11        debounce = false
12    end
13end)

Hope this helps! Comment if something doesnt work, because i tested it and it should work.

Answer this question