Problem:
For some reason you are referencing to the state being Changed in the TextLabel instead of referencing to the actual player's data. Then you are also referencing to a Changed state in the "playerstats", Where I presume is the folder holding the Exp value.
Solution:
Simply find when the value of the player's specific data is changed. In this case would be the EXP.
(I don't know why you have a wait at the top but it may be a chunk of your script so I will leave it).
I would highly recommend using :WaitForChild() when you do not know that the particular thing you are looking for in your script will be there whether it be because of loading issues or something along the lines of a player joining the game.
Code Below:
wait(6)
local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local gui = playergui:WaitForChild("expguiTest")
local explabel = gui:WaitForChild("TextLabel")
Next I would add a variable to reference to the player's Data.
local stats = player:WaitForChild("playerstats")
local Exp = stats:WaitForChild("EXPValue")
Then I would fix the Changed event for the value, which is the Exp in your case. I would also take the Gui Changed event out too.
Exp.Changed:Connect(updateHud)
Lastly, I don't see anything wrong in your function other than changing to :WaitForChild() so.
function updateHud()
explabel.Text = "" ..player::WaitForChild("playerstats"):WaitForChild("EXPValue").. " EXP"
end
All together we have:
wait(6)
local player = game.Players.LocalPlayer
local playergui = player:WaitForChild("PlayerGui")
local gui = playergui:WaitForChild("expguiTest")
local explabel = gui:WaitForChild("TextLabel")
local stats = player:WaitForChild("playerstats")
local Exp = stats:WaitForChild("EXPValue")
function updateHud()
explabel.Text = "" ..player::WaitForChild("playerstats"):WaitForChild("EXPValue").. " EXP"
end
Exp.Changed:Connect(updateHud)
If you have any problems or still don't understand what I typed/did just let me know in the comments.
4 comments
BTW, EXPValue's parent is in playerstats. playerstat's parent is Player.
why do you check that explabel has changed.. it won't change you'll have to do a while true do
Please don't do a loop, triggering it off an event is doable. While True loops are the BANE of good programmers
Line 9, the text would be " EXPValue EXP" Because you didn't tell it to read the VALUE of EXPValue, just the pathway to it.