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

How to check if a TextLabel's text was changed?

I'm creating a GUI system that creates a Team with a desired name that the player inputs into a TextLabel on the GUI. I have it all working correctly except for a part where the script is supposed to check if the TextLabel's Text was changed and, if so, it should print what was changed. The problem is that "AbsolutePosition" is printed so many times after the GUI Frame moves into it's Position, when :TweenPosition() was used. Below is the script.


local teamName = ""
local CreateTeamGui = script.Parent
local CreateTeamActivated = false

function nameInput(name)
	if CreateTeamActivated == true then
		for i = 1, #name do
			teamName = string.sub(name, 1, i)
		end
		print(teamName) --This is what's printed when TeamNameLabel.Changed is called
	end
end

script.Parent.Parent.GuiHandler.ForCreateTeam.OnServerEvent:connect(function() --Event is called when the player clicks on a button to Create a Team then checks for the following:
	if script.Parent.Parent.CreateTeamActive == false then
		return
	else
		CreateTeamActivated = true
	end
end)

CreateTeamGui.TeamNameLabel.Changed:connect(nameInput) --I tried other things and of course doing TeamNameLabel.Text.Changed is not a thing... :C

I believe that something on wiki's string manipulation page should help with this partly but I have no idea what. If anything else you guys think should be changed then please add that to your answer. So Appreciated, Much Thanks.

2 answers

local teamName = ""
local CreateTeamGui = script.Parent
local CreateTeamActivated = false
CreateTeamGui.TeamNameLabel:connect(function()
    if CreateTeamActivated == true then
        for i = 1, #name do
            teamName = string.sub(name, 1, i)
        end
        print(teamName) --This is what's printed when TeamNameLabel.Changed is called
    end
end)

script.Parent.Parent.GuiHandler.ForCreateTeam.OnServerEvent:connect(function() --Event is called when the player clicks on a button to Create a Team then checks for the following:
    if script.Parent.Parent.CreateTeamActive == false then
        return
    else
        CreateTeamActivated = true
    end
end)

Yeah, this might work. Sometimes it is better to do the function first :)

1 comment

0

What you did had not done anything to really fix the problem. This actually doesn't do anything at all.

Changed gives both the property that changed, and it's new value
Try changing your function to this

function nameInput(property)
    if CreateTeamActivated == true then
        if property == 'Text' then
print(textThingy.Text) -- what the Text was changed to. Change textThingy to suit your code.
end
    end
end

I apologise in advance for the tabbing. There doesn't appear to be a tab button on the iOS keyboard.

2 comments

0

I see what you're trying to do but when I tried implementing this to my code, in the output, "property" is returning nil? How would I set that to "CreateTeamGui.TeamNameLabel.Text"?

0

My mistake. I'd assumed that it also gave you the value it changed to, but apparently that's only valid with Value type Instances. I've updated my code to reflect this.

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