Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make a text label in a surface gui change through script?

Im doing code where i make the text the name of the parts parent like

while true do
	wait(1)
	if script.Parent.Parent.Parent.Parent.Name == "Workspace" then
		script.Parent.TextLabel.Text = "Wait"
	else
		script.Parent.Text = script.Parent.Parent.Parent.Name
		print("Changed")
	end
end

But when i change the parts parent manually the text doesent change. how can i make it so it "Refreshes"

1 answer

local tl = script.Parent.TextLabel
tl.Parent.Parent:GetPropertyChangedSignal("Parent"):Connect(function(p)
	if p ~= workspace then
		tl.Text = "Wait"
	else
		tl.Text = p.Name print("changed")
	end
end)

getpropertychangedsignal will fire when tl.Parent.Parent.Parent is changed and will run the function i made which should set the text label text to the new parent's name

if i got a parent directory wrong you should still be able to change a couple of things and it will still work

This discussion is preserved as it was. New answers, comments, and votes are closed.