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

Why won't this Label's text change?

Asked by
FizTech 15
8 years ago

I am trying to make the TextLabel's text to change depending on how much gold I have. I don't know if I am doing anything wrong. There is no output. I am fairly new to scripting so i'm sorry if the mistake is rather obvious. This is located in server script storage.

Thanks.

local player = game.Players.LocalPlayer--Finds the player
local gui = player:WaitForChild("PlayerGui").GoldHolder--Finds the gui
local gold = player:WaitForChild("leaderstats").Gold--Finds the gold in the leaderstats
local button = gui.TextLabel--Finds the label

game.Players.PlayerAdded:connect(function()
    print("Hello")--Doesn't print
    button.Text = "Gold "..gold.Value
end)
0
Little tip. You don't need to use a player added event in a local script. This LocalScript will get replicated to the player meaning... Well... Meaning a player added event is never needed in a local script. This might even be your problem, I'm not sure. Try removing lines 6 and 9. User#11440 120 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Well, you know the way you're doing is definitely wrong... (I am )

So,

Before we start off, here's some things you need to be proficient or atleast good at or know the usage of ~ The Client and the Server ~ Remote Event and Remote Function ~ Also, a simple understanding of a GUI

If you know them all, We're good to go! YAY! =D

Let's get over the task here.

Your goal You want to display the amount if gold a certain player has in his account/inventory.

Lets begin with understanding our framework now.

Client The client should hold a gui, which will show the player the current amount of coins. Server The server will be used to update the data on the server

Ok, Lets begin with a local script =P

local Player = game:GetService("Players").LocalPlayer  -- Locate our player ;)
local PlayerGui = Player:WaitForChild("PlayerGui")  -- Wait for the Player GUI to load on client
local Gold = Player:WaitForChild("leaderstats").Gold -- Wait for the children to load, aka our leaderstats etc
local GoldLabel = PlayerGui:FindFirstChild("Gold", true) --  Find the label in which we want to show our text

Gold.Changed:connect(function(ChangedProperty)  -- Whenever the Gold Value is changed by the server script, an event is fired, this event is called a Changed event, We take this event to do magic
    if ChangedProperty == "Value" then  -- See if the property that is changed is actually Value and not the name or any other property xD
        GoldLabel.Text = Gold.Value -- If it's the Value that's changed, update our text! WOOO 
    end
end)

Alright That was bad, ik but hey I think I gave some rough Idea =D

Hopefully it helps ya, and to the pros, If I have done anything wrong here pls FIGHT MY CODE (I mean fix me and my code )

~Eat Caiks

0
ServerScriptService.Leaderboard.Script:4: attempt to index local 'player' (a nil value) -- This is what it says when I run the script FizTech 15 — 8y
0
Please do note that, I only gave a sample code, you need to follow the instructions and use your own brain to fix the problem. I gave you the important pieces, you will have to finish the puzzle ;) buoyantair 123 — 8y
Ad

Answer this question