i need to know how to save for my simulator so yeah im kinda dumb as crap :D so yeah also if u can help me with developer products that increase leader stats that would help 2 :D my leaderstat is called "Muscle"
COMMUNITY QUESTION
Script To Save data leaderstats and where to make script?
3 answers
I seriously need help
Here, I wrote a script for you:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(player)
local MuscleValue = player:WaitForChild("leaderstats"):WaitForChild("Muscle")
local Data
local Success, ErrorMessage = pcall(function()
Data = DataStore:GetAsync(player.UserId.."-Muscle")
end)
if Success then
MuscleValue.Value = tonumber(Data)
else
print("There was an error loading "..player.Name.."'s data.")
warn(ErrorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Success, ErrorMessage = pcall(function()
DataStore:SetAsync(player.UserId.."-Muscle", player:FindFirstChild("leaderstats"):FindFirstChild("Muscle"))
end)
if Success then
print(player.Name.."'s Data was successfully saved.")
else
print(player.Name.."'s Data failed to save.")
warn(ErrorMessage)
end
end)
An in-depth explanation would be very long and impractical to put here, so here's a link to one if you would like to know how this script works.
Use data store, use a normal script, and put it in serverscriptservice or workspace https://developer.roblox.com/en-us/articles/Data-store
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
To use this script, place I would recommend placing it inside of ServerScriptService.
didnt work'
my tool isnt owrkin now....