Answered by
6 years ago Edited 6 years ago
Your LocalScript is most likely running too early for the PlayerStats to be created, and as a result, it is not parented under the player yet.
By adding a local variable pertaining to the "PlayerStats" and using "WaitForChild()" you can make sure that the functions are only able to be run when "PlayerStats" is a member of the player.
01 | local Player = game.Players.LocalPlayer |
02 | local Stats = Player:WaitForChild( "PlayerStats" ) |
03 | local BagText = script.Parent.BagLabel |
04 | local CoinText = script.Parent.CoinLabel |
06 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
07 | local RemoteEvents = ReplicatedStorage.RemoteEvents |
09 | BagText.Text = ( "Bag: " ..Stats.CurrentValue.Value.. "/" ..Stats.Storage.Value) |
10 | CoinText.Text = ( "Coins: " ..Stats.Coins.Value) |
12 | Stats.CurrentValue:GetPropertyChangedSignal( "Value" ):Connect( function () |
13 | BagText.Text = ( "Bag: " ..Stats.CurrentValue.Value.. "/" ..Stats.Storage.Value) |
17 | Stats.Coins:GetPropertyChangedSignal( "Value" ):Connect( function () |
18 | CoinText.Text = ( "Coins: " ..Stats.Coins.Value) |
In order to be extra sure, you can do the same for the values inside the function
01 | local Player = game.Players.LocalPlayer |
02 | local Stats = Player:WaitForChild( "PlayerStats" ) |
03 | local Current = Stats:WaitForChild( "CurrentValue" ) |
04 | local Storage = Stats:WaitForChild( "Storage" ) |
05 | local Coins = Stats:WaitForChild( "Coins" ) |
07 | local BagText = script.Parent.BagLabel |
08 | local CoinText = script.Parent.CoinLabel |
10 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
11 | local RemoteEvents = ReplicatedStorage.RemoteEvents |
13 | BagText.Text = ( "Bag: " ..Current.Value.. "/" ..Storage.Value) |
14 | CoinText.Text = ( "Coins: " ..Coins.Value) |
16 | Current:GetPropertyChangedSignal( "Value" ):Connect( function () |
17 | BagText.Text = ( "Bag: " ..Current.Value.. "/" ..Storage.Value) |
21 | Coins:GetPropertyChangedSignal( "Value" ):Connect( function () |
22 | CoinText.Text = ( "Coins: " ..Coins.Value) |