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

Leaderstats With DataStore Failure?

Asked by 4 years ago

When a value incercrases, it doesn't saves with DataStore, here is the script:

01local DataStoreService = game:GetService("DataStoreService")
02 
03local myDataStore = DataStoreService:GetDataStore("myDataStore")
04 
05 -- Creates a leaderboard that shows player variables
06    local function onPlayerJoin(player)
07        local leaderstats = Instance.new("Folder")
08        leaderstats.Name = "leaderstats"
09        leaderstats.Parent = player
10 
11        local gold = Instance.new("IntValue")
12        gold.Name = "Gold"
13        gold.Value = 0
14        gold.Parent = leaderstats
15 
View all 67 lines...
0
Does any of "print()" actually print something? KrzysiekRoblox 50 — 4y
0
Yes NerfLambdaWarrior120 3 — 4y
0
This wont solve your issue but you can set the parent of an instance as the second argument of the instance constructor. E.g: local myPart = Instance.new("Part", workspace) SuchASaltyLemon 35 — 4y
0
So, if yes, which one prints something? KrzysiekRoblox 50 — 4y
View all comments (3 more)
0
lemme check NerfLambdaWarrior120 3 — 4y
0
it doesn' t prints something (i confused with the script of the BuyButton that i putted in the game) NerfLambdaWarrior120 3 — 4y
0
here you have the link of the game (wich is uncopylocked and it it's just a test for the script for the original one) LINK: https://www.roblox.com/games/5023928146/Untitled-Game NerfLambdaWarrior120 3 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

First things first, "player" in lines 35-37 is not defined anywhere. Script doesn't understand what 'player' is.

Second, "gold", "items" and "spaces" in lines 52-54 are also not defined. Even if you create a variable in function, it doesn't work outside it.

I think your problem is, that you don't understand how to use scopes. Here's a Roblox tutorial about it: https://developer.roblox.com/en-us/articles/Scope

Also, there's a nice Roblox tutorial that explains how to correctly save player's data on exit: https://developer.roblox.com/en-us/articles/Saving-Player-Data

Making it the way you've done it is a bad practice. After player leaves the game script can't access "leaderstats" object, because it's already gone. You should do this the way as it's shown in the second link :)

And also, when you test DataStore, I recommend doing it in actual game, not in Roblox Studio. DataStore in Roblox Studio doesn't always work with game.Players.PlayerRemoving.

Hope I helped :)

Ad

Answer this question