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

I need help i want this leaderstat value "epicness" to be saved can anyone show me how?

Asked by 5 years ago
Edited by royaltoe 5 years ago
01local function onPlayerJoin(player)
02    local leaderstats = Instance.new("Folder")
03    leaderstats.Name = "leaderstats"
04    leaderstats.Parent = player
05 
06    local Epicness = Instance.new("IntValue")
07    Epicness.Name = "Epicness"
08    Epicness.Value = 0
09    Epicness.Parent = leaderstats
10 
11end
12 
13game.Players.PlayerAdded:Connect(onPlayerJoin)

2 answers

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

If anyone viewing has a similar issue, we talked it over over discord and came up with this solution:

Comments are there explaining what each bit of code does, but comment if you need anymore explanation.

01local DataStoreService = game:GetService("DataStoreService") --allows us to use datastores
02local epicnessDatastore = DataStoreService:GetDataStore("EpicnessDatastore") --our datastore for saving the epicness value
03 
04 
05--onPlayerJoin runs whenever the player joins the game.
06function onPlayerJoin(player)
07    --creates an `epicness` intvalue for each player in the leaderboards.
08    local leaderstats = Instance.new("Folder")
09    leaderstats.Name = "leaderstats"
10    leaderstats.Parent = player
11 
12    local Epicness = Instance.new("IntValue")
13    Epicness.Name = "Epicness"
14    Epicness.Value = 0
15    Epicness.Parent = leaderstats
View all 42 lines...
Ad
Log in to vote
1
Answered by 5 years ago

Assuming you already have a leaderstats, add something like this to it.

01game.Players.PlayerAdded:Connect(function(plr)
02    local epicness = Instance.new("IntValue", folder)
03    epicness.Name = "Epicness"
04 
05 
06    epicness.Value = NameOfYourDataStore:GetAsync(plr.UserId)
07    NameOfYourDataStore:SetAsync(plr.UserId, epicness.Value)
08 
09    epicness.Changed:connect(function()
10        NameOfYourDataStore:SetAsync(plr.UserId, epicness.Value)
11end)

Answer this question