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

Help on this GUI text script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

I have a script that is meant to display the text of a TextLabel as an IntValue is a player. It is in the PlayerGUI as is the Apples IntValue. (Image here: http://mystdar-roblox.deviantart.com/art/Apples-487189581?ga_submit_new=10%253A1412791523)

The script is like this

while wait(.1) do
local apple_count = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Apples
script.Parent.Text= "Apples:" .. apple_count.Value 
end

I aim to make it only fire/occur when the value is changed, if you could help with that too, that would be great. Thanks.

3 answers

Log in to vote
2
Answered by 10 years ago

Try making your code more efficient. You could easily just use game.Players.LocalPlayer instead of using the Parent property repetitively (like Spectrobz and MrSmenry have kept it as.)

Also, you can use the Changed event to check when a property changes in an Instance (in this case, the Value property.)

Try using this in a LocalScript:

local player = game.Players.LocalPlayer --The local player.
local apples = player:WaitForChild("Apples") --Yields (makes the script wait) until the apples object becomes available.

apples.Changed:connect(function() --Connects a function to an event. Known as an anonymous function (as it has no direct identifier.)
    script.Parent.Text = "Apples: " .. apples.Value --Sets the Text property of the script's parent to "Apples: " then the apples variable's value. The two dots are used for string concatenation (merging of values to form a string.)
end) --Ends the anonymous function.
0
Is apples:Changed meant to be apples.Changed? Mystdar 352 — 10y
0
This one works, thanks, one small error, (on my part) the script only fires when it is changed, so until the unit is changed it just says Apple: Any help? Mystdar 352 — 10y
1
Yeah, good eyes. Ha ha. Also, just set the Text property of the script's parent to "Apples: 0" (without the quotes) initially.  Spongocardo 1991 — 10y
0
That would only work if their one was 0, I intent to save this Int so if someone rejoined and had 20 apples, then it wouldn't be one, yes? Thanks for the compliment, btw. Mystdar 352 — 10y
View all comments (2 more)
0
Yeah, copy line 5 to line 3 so that it sets the text property to the Apples value before the Changed event occurs. Spongocardo 1991 — 10y
0
Alright, thanks. Mystdar 352 — 10y
Ad
Log in to vote
1
Answered by
Spectrobz 140
10 years ago

Here you go ;)

local apples = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Apples

apples.Changed:connect(function()
script.Parent.Text= "Apples:" .. apples.Value
end)

0
Doesn't work for me, I just get this: http://mystdar-roblox.deviantart.com/art/Apple-GUI-487194079?ga_submit_new=10%253A1412793106 The GUI's normal text is Apples: And it doesn't work/change it.I have tried your script in a local one and normal Mystdar 352 — 10y
0
Did you check your output window for errors? Did you check if the text wasn't blank in case you had it hidden or something? Spongocardo 1991 — 10y
Log in to vote
0
Answered by
Relatch 550 Moderation Voter
10 years ago
while wait(.1) do
    local apple_count = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Apples
    script.Parent.Text = "Apples:" .. apple_count.Value 

    apple_count.Changed:connect(function()
        script.Parent.Text = "Apples:" ..apple_count.Value
    end)
end

If this does not work, please contact me any errors you receive.

Answer this question