Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why leaderstats is not a valid member of Player?

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..

local Coins = script.Parent.Parent.Parent.Parent.leaderstats.Coins
Coins.Changed:Connect(function()
	script.Parent.Text = "$: "..Coins.Value
end)

can somene help?

3 comments

0

Where is this script located? Where is the script that creates the leaderstats?

0

In a TextLabel in ScreenGui in StarterGui

0

^ Make sure the script that makes the leaderstats is a ServerScript and make sure that you insert it into ServerScriptService.

4 answers

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:

local plr = game.Players.LocalPlayer
local Coins = plr:WaitForChild("leaderstats"):WaitForChild("Coins")
local CoinsText = script.Parent

Coins:GetPropertyChangedSignal("Value"):Connect(function()
	CoinsText.Text = "$: "..Coins.Value
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)

local player = game.Players.LocalPlayer
local coins = player:WaitForChild('leaderstats').Coins

coins:GetPropertyChangedSignal('Value'):Connect(function()
script.Parent.Text = '$ ' ..coins.Value.. '.'

Please let me know if it works or not after you apply my code to your game.

4 comments

0

Changed is an event.

0

Wth, i tought my comment were posted

0

I said that it actually worked fine, but, when you grab the Coins with value of 5 the leaerboard doesnt work, but if you grab the Coin of 1e18+ it does work but weird

0

I think i can.. @skvyyy

Try this with a server script:

Assuming you have a ScreenGui named MoneyDisplay with a TextLabel, insert the following into ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	-- Assuming you have the leaderstats set up
	local Coins = player:WaitForChild("leaderstats").Coins
	Coins.Changed:Connect(function()
		player.PlayerGui.MoneyDisplay.TextLabel.Text = "$"..(Coins.Value)
	end)
end)

Try:

Player:WaitForChild("Leaderstats")

2 comments

0

local Coins = game.Players.LocalPlayer:WaitForChild("Leaderstats") -- Am i right?

0

yeah as it wont show in studio but will wait for it in game, but game.Players.LocalPlayer wont work in a normal script only local

This discussion is preserved as it was. New answers, comments, and votes are closed.