Yup, it is not, i have some script for showing the mony that you got (In the screen, not the leaderboard) first it were good but later it said "leaderstats is not a valid member of Player"
Here's the script..
1 | local Coins = script.Parent.Parent.Parent.Parent.leaderstats.Coins |
2 | Coins.Changed:Connect( function () |
3 | script.Parent.Text = "$: " ..Coins.Value |
4 | end ) |
can somene help?
You should use a local script in your TextLabel in your Screen Gui Instead of a regular script and trying to find the player from the PlayerGui.
The code in the local script should go something like this:
1 | local plr = game.Players.LocalPlayer |
2 | local Coins = plr:WaitForChild( "leaderstats" ):WaitForChild( "Coins" ) |
3 | local CoinsText = script.Parent |
4 |
5 | Coins:GetPropertyChangedSignal( "Value" ):Connect( function () |
6 | CoinsText.Text = "$: " ..Coins.Value |
7 | end ) |
Firstly, using the whole "script.Parent.Parent.Parent.Parent" method gets the player's Character
, not the Player
itself.
Secondly, you are edit anything related to GUI
's via a ServerScript
. Try using a LocalScript instead.
Thirdy, :Changed()
is not an Instance
to my knowledge. You'd have to use :GetPropertyChangedSignal
instance instead.
Anyways, here's your fixed code (make sure to put it into a LocalScript
)
1 | local player = game.Players.LocalPlayer |
2 | local coins = player:WaitForChild( 'leaderstats' ).Coins |
3 |
4 | coins:GetPropertyChangedSignal( 'Value' ):Connect( function () |
5 | script.Parent.Text = '$ ' ..coins.Value.. '.' |
Please let me know if it works or not after you apply my code to your game.
Try this with a server script:
Assuming you have a ScreenGui named MoneyDisplay with a TextLabel, insert the following into ServerScriptService:
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | -- Assuming you have the leaderstats set up |
3 | local Coins = player:WaitForChild( "leaderstats" ).Coins |
4 | Coins.Changed:Connect( function () |
5 | player.PlayerGui.MoneyDisplay.TextLabel.Text = "$" ..(Coins.Value) |
6 | end ) |
7 | end ) |
Try:
1 | Player:WaitForChild( "Leaderstats" ) |