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

Why leaderstats is not a valid member of Player?

Asked by 4 years ago

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?

0
Where is this script located? Where is the script that creates the leaderstats? DeUltimate23 142 — 4y
0
In a TextLabel in ScreenGui in StarterGui El_Tycoonero0Delgado 18 — 4y
0
^ Make sure the script that makes the leaderstats is a ServerScript and make sure that you insert it into ServerScriptService. zane21225 243 — 4y

4 answers

Log in to vote
1
Answered by 4 years ago

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)

Ad
Log in to vote
0
Answered by
zane21225 243 Moderation Voter
4 years ago

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.

0
Changed is an event. SirGamezy 186 — 4y
0
Wth, i tought my comment were posted El_Tycoonero0Delgado 18 — 4y
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 El_Tycoonero0Delgado 18 — 4y
0
I think i can.. @skvyyy El_Tycoonero0Delgado 18 — 4y
Log in to vote
0
Answered by
SirGamezy 186
4 years ago

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)
Log in to vote
0
Answered by 4 years ago

Try:

Player:WaitForChild("Leaderstats")
0
local Coins = game.Players.LocalPlayer:WaitForChild("Leaderstats") -- Am i right? El_Tycoonero0Delgado 18 — 4y
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 gringlestick2 -178 — 4y

Answer this question