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