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

How to save a gui value using datastore??

Asked by 8 years ago
Edited 8 years ago

I'm trying to make it so when a stat changes, it saves. It isn't s stupid leaderstat. It's a IntValue inside a Gui. This is what I have so far; it doesn't work at all. I'm new to datastore and personally think it's stupid. I was just trying to save the ki value but still added the stamina and attack for later.

There are no errors. The problem is that the Ki value won't save

01--Btw this is a script in Workspace
02 
03local DataStore = game:GetService("DataStoreService"):GetDataStore('SSJClickerSaves')
04 
05game.Players.PlayerAdded:connect(function(Player)
06    local PlayerId = 'id-'.. Player.userId
07    local Ki = Player.PlayerGui.Stats.StatsFrame.Ki:FindFirstChild("KiVal")
08    local Attack = Player.PlayerGui.Stats.StatsFrame.Physical:FindFirstChild("AttackVal")
09    local Stamina = Player.PlayerGui.Stats.StatsFrame.Stamina:FindFirstChild("StamVal")
10 
11    local Save = DataStore:GetAsync(PlayerId)
12    if Save then
13        Ki.Value = Save[1]
14 
15        local SaveValues = {Ki.Value}
View all 26 lines...

This is for a DBZ game I'm making. It's in the pre-est of pre alphas.

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

First things first, your code will not support FilteringEnabled

Do not access the Player's PlayerGui in a Server-Script this will throw errors.

-- in a localscript under StarterGui or StarterPlayer.StarterPlayerScripts

01-- Variables
02 
03local DataStoreService = game:GetService("DataStoreService") -- Get Service
04local DataStore = DataStoreService:GetDataStore("SSJClickerSaves") -- Get DataStore
05 
06local Player = game.Players.LocalPlayer -- Get LocalPlayer i.e Player
07local Key = "user_" .. Player.UserId -- Get the UserId
08 
09local PlayerGui = Player.PlayerGui -- Access PlayerGui
10local Stats = PlayerGui.Stats -- Get Stats
11local SFrame = Stats.StatsFrame -- Get StatsFrame
12 
13local Ki = SFrame.Ki:FindFirstChild("KiVal") -- Get Ki
14local Attack = SFrame.Physical:FindFirstChild("AttackVal") -- Get Attack
15local Stamina = SFrame.Stamina:FindFirstChild("StamVal") -- Get Stamina
View all 35 lines...
0
Although your script didn't quite work, I appreciate all the effort. Also, this gave me a better idea of how the dataStore works <3 animelover6446 41 — 8y
0
no problem, good luck! DragonSkyye 517 — 8y
0
I would not use a changed event to save player stats, this will exceed the limitations. User#5423 17 — 8y
Ad

Answer this question