Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
xPolarium 1388 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by 8 years ago
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 :)

0
What you did had not done anything to really fix the problem. This actually doesn't do anything at all. xPolarium 1388 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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.

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"? xPolarium 1388 — 8y
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. User#6546 35 — 8y

Answer this question