Invalid argument #3 (string expected, got Instance)

I’m trying to make it so a TextLabel will display a constantly changing IntValue, in this case it’s named HungerVal and it is a child of the Player.

I’m getting the error of:
invalid argument #3 (string expected, got Instance)

This is the script that is under the TextLabel


local text = script.Parent
local plr = game.Players.LocalPlayer

wait(1)

while true  do
	
script.Parent.Text = plr.HungerVal -- where the error is

end

This is what the explorer looks like
Screenshot_49

Any help on this would be greatly appreciated

Probably you forgot to add .Value afther plr.HungerVal, and also i would suggest adding a wait() inside the while true loop

Hello. Please use plr.HungerVal.Value (assuming it is a string value).

local text = script.Parent
local plr = game:GetService("Players").LocalPlayer

task.wait(1)

while true do
task.wait()
script.Parent.Text = plr.HungerVal 
end

Add a .Value to plr.HungerVal if it is a value like @FamorBlox said. The loop will get exhausted because there is no wait. Also I recommend to use task.wait() instead of wait().

1 Like

Also, I would suggest using the .Changed method as it is much more efficient that updating a value frequently.

1 Like