|
| 20 Nov 2015 10:14 PM |
Hey. Learning to get into more advanced scripting (not sure if DataStores are considered advanced or not).
Anyway, I have a two scripts in workspace.
1: local DataStore = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerAdded:connect(function(player)
local coins = player.PlayerGui.ScreenGui.Coin.TextLabel.Value.Value
local key = "player-"..player.userId local savedValues = DataStore:GetAsync(key)
if savedValues then coins.Value = savedValues[1] else local valuesToSave = {coins.value} DataStore:SetAsync(key, valuesToSave) end end) ----------------------------------------------------------------- 2. local DataStore = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerRemoving:connect(function(player)
local key = "player-"..player.userId
local valuesToSave = {player.PlayerGui.ScreenGui.Coin.TextLabel.Value.Value} DataStore:SetAsync(key, valuesToSave) end) -----------------------------------------------------------------
And basically, I have a GUI with a textlabel that shows the value's number. (I doubt the textlabel has to do with the problem.)
I've gotten one error: ScreenGui is not a valid member of PlayerGui
That's the correct name and path to the Value. Help?
|
|
|
| Report Abuse |
|
|
|
| 20 Nov 2015 10:34 PM |
| Use WaitForChild to make sure it's there before you try to access it. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2015 11:23 PM |
@Swag
Not getting that error anymore, but now I'm getting a new?(may have missed it?) error:
Workspace.onPlayerAdded:15: attempt to index local 'coins' (a number value) |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2015 11:26 PM |
local coins = player.PlayerGui.ScreenGui.Coin.TextLabel.Value.Value
That doesn't look right. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2015 11:28 PM |
@Swag
What do you mean?...
The coin is an imagelabel, the textlabel is the text that displays the Value. |
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 20 Nov 2015 11:56 PM |
player.PlayerGui.ScreenGui.Coin.TextLabel.Value.Value
Since it's a TextLabel, to access the string within it you would do:
player.PlayerGui.ScreenGui.Coin.TextLabel.Text
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2015 11:59 PM |
@Ty
Am I missing something?
There's a literal NumberValue inside the TextLabel
Would it still be TextLabel.Text? |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 12:16 AM |
| I am actually 200% sure you did not write that code. |
|
|
| Report Abuse |
|
|
Dogejia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 1873 |
|
|
| 21 Nov 2015 12:17 AM |
Maybe UpdateAsync?
Dogemon, gotta pet them all! |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 12:27 AM |
@Swag
I mostly based it off Youtube videos and the Wiki.
Didn't copy & paste it though.
@Dog
These scripts should work without UpdateAsync I think. |
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 12:48 AM |
Wait, quick question, why did you put a NumberValue inside of a TextLabel? Wouldn't it be easier to put it in the TextLabels parent? Eh, that's just me ranting.
Since it's not the string you're trying to get and the NumberValue's value, you would do:
player.PlayerGui.ScreenGui.Coin.TextLabel.NumberValue.Value
Could I ask what "Coin" is? (ClassName (i.e. part, frame, textlabel, folder, etc.))
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:05 AM |
@Tyokii
I'm sure you can tell I'm inexperienced; I just recently began working with more advanced scripts and functions.
I probably should change the "Value" back to NumberValue, would confuse me less. But this doesn't fix the problem.
"Coin" is an ImageLabel with a picture of a coin. There's a textlabel over it showing the NumberValue's value to show the number of coins you have. I already made an actual coin, where you touch it it gives you 5 (will normally be 1, set it to 5 for testing) coins, or sets the NumberValue's value to "5". Then the textlabel (updates using a while true do) switches to the NumberValue's value.
|
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 01:09 AM |
So, to recap:
NumberValue - Stored somewhere random, the integer used for the coin's amount. Coin - ImageLabel TextLabel - Over the Coin, constantly updating the text to match the NumberValue's value.
If this is true, I would just suggest moving NumberValue in ReplicatedStorage, the player, or in the ScreenGui. Regards for my full on ignorance, I've been trying to fix two issues for the past two hours and I'm just getting really tired.
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:17 AM |
@Ty
I moved the NumberValue so the ScreenGui was the parent, and updated all the paths for the two scripts.
I have 1 script in Workspace named "onPlayerAdded" here:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerAdded:connect(function(player)
player.PlayerGui:WaitForChild("ScreenGui")
local coins = player.PlayerGui.ScreenGui.NumberValue.Value
local key = "player-"..player.userId local savedValues = DataStore:GetAsync(key)
if savedValues then coins.Value = savedValues[1] else local valuesToSave = {coins.value} DataStore:SetAsync(key, valuesToSave) end end)
And another script in Workspace called "onPlayerRemoved" here:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Test")
game.Players.PlayerRemoving:connect(function(player)
local key = "player-"..player.userId
local valuesToSave = {player.PlayerGui.ScreenGui.NumberValue.Value} DataStore:SetAsync(key, valuesToSave) end)
Can you tell what I've done wrong?
|
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 01:18 AM |
Could you paste the output? It'll make spotting the bug 10x easier.
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:23 AM |
Here's the only error I could find:
02:20:18.622 - Workspace.onPlayerAdded:13: attempt to index local 'coins' (a number value) 02:20:18.622 - Stack Begin 02:20:18.622 - Script 'Workspace.onPlayerAdded', Line 13 02:20:18.623 - Stack End
|
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:26 AM |
local coins = player.PlayerGui.ScreenGui.NumberValue.Value
Fix this noob. |
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 01:28 AM |
I really have no clue, that's odd. I'll look at it tomorrow and see if I can find anything, maybe I'm just blind tonight.
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:29 AM |
@Swag
See that's the thing
how. I don't really see what's wrong there. Does "coin" have to be a number? |
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 01:31 AM |
@SwagCuzYolo
Hey man, that's a bit harsh. Go easy on him, he's only a beginner. We've already tried that and still gotten the same error, reading is a crucial key to defining the issue, and I'm not sure that you've done that.
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:34 AM |
local coins = player.PlayerGui.ScreenGui.NumberValue.Value
Read this, idiot. |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:36 AM |
@Swag
Still not getting what you're trying to say. |
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 01:39 AM |
Look, kid, if you're going to refuse to read everything that we already stated in the thread, then just get out. We don't want arrogant scumbags like you just reiterating what was already aforementioned in the first post, but not only are you doing that, but you're doing it in such a rude manner. Nobody wants you here, nobody wants your "help", so just leave.
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2015 01:39 AM |
local coins = player.PlayerGui.ScreenGui.NumberValue.Value
Read this, dumbass. |
|
|
| Report Abuse |
|
|
Tyokii
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 754 |
|
|
| 21 Nov 2015 01:42 AM |
Are you visually or mentally impaired? Because if you are, I'll completely drop everything I just said and let you continue to act like a lost puppy.
[ insert neat siggy here ] |
|
|
| Report Abuse |
|
|