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

How to activate a function after another function ends?

Asked by
emite1000 335 Moderation Voter
9 years ago

Background: Once some text appears on-screen, I want a separate thing thing of text to appear. So I decided to use :connect() to make the next function go after the first.

Code:

--Some stuff above here that makes stuff happen and activates what's below.
    Txt = Instance.new("TextBox", scrl)
        Txt.Position = UDim2.new(0.1, 0,0.2, 0)
        Txt.BackgroundTransparency = 1
        Txt.Size = UDim2.new(0.75, 0, 0.56, 0)
        Txt.Font = 4
        Txt.FontSize = 7
        Txt.TextYAlignment = ("Top")
        Txt.TextWrapped = true
        Txt.Text = ("My text goes here")
        Txt.Changed:connect(Response)
end

function Response()
    Rpns = Instance.new("TextButton", scrl)
        Rpns.Position = UDim2.new(0, 40,0.78, 0)
        Rpns.Size = UDim2.new(0.75, 0,0, 10)
        Rpns.BackgroundTransparency = 1
        Rpns.Font = 1
        Rpns.FontSize = 4
        Rpns.TextColor3 = Color3.new(255, 0, 0)
        Rpns.AutoButtonColor = false
        Rpns.Text = ("My response goes here")
end

Problem: However, since I used the Changed event (since it was the only one I could think of to use to activate the :connect()) for some reason it makes two identical Textbuttons appear. They are in the same position and everything. Why is this happening, and how do I fix it?

1 answer

Log in to vote
0
Answered by 9 years ago

Hello. After reading your script and question, I think I may have found a good answer.


Instead of using the line Txt.Changed:connect(Response) you should use a different type of function.

On the Response function, instead of function Response() do the following:

txt.Changed:connect(function()
    -- your code here
end)

Then as soon as a property is changed, that code will run. You will have no need for the connect line in the first function.


Another thing you could do instead of doing what I instructed above, you can change that Txt.Changed:connect(Response) to Response(). I'm not sure how much positioning of the functions matters, but if you do this way and it doesn't work or outputs an error of some sort, put the Response function above the first function you posted.

If you try both of these, and neither work, please let me know. If you have any questions, please ask! Thanks!

0
I tried your first method, but it didn't seem to solve the problem. In fact, it actually made 4 appear instead of 2. emite1000 335 — 9y
0
Did you try the second method? TheStudentPilot 75 — 9y
Ad

Answer this question