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

Text button function problems? [Solved]

Asked by 4 years ago
Edited 4 years ago

So my question is this: What's wrong with my code? and how can I fix it?

local Input_Service=game:GetService("UserInputService")

local Select_Color =Color3.new(1,1,1)
local Default_Color =Color3.new(0.5,0.5,0.5)

local Buttons =script.Parent.Buttons

local function New_Bind(Key,Text_Front)
    Key.Text ="Enter new key..."--Text changes here as intended.
    Key.TextColor3 =Select_Color--This works.
    Input_Service.InputBegan:Connect(function(input)
        local Key =string.split(tostring(input.KeyCode),".")
        Key.TextColor3 =Default_Color--Color won't change here!
        Key.Text =Text_Front..'('..Key[3]..')'--This isn't working! Text won't change here.
        print(Text_Front..'('..Key[3]..')')--Outputting text is correct, won't change the button!
    end)
end

Buttons.KEY_Button.MouseButton1Click:Connect(function()
    New_Bind(Buttons.KEY_Button,'Key =')
end)

What this is supposed to do: When you click on a text button("KEY_Button"), the button's text changes to "Enter new key...". Then it waits for the next key you press, and changes the button's text again depending on what the key you pressed was. The function then "stops" or "resets" so it doesn't fire when you press any more buttons. (until you click the text button again)

I'm having two problems with it: The first is that it isn't changing the buttons text the second time. (to "Key =The key pressed")

and the second problem is that I'm unsure of the best way to stop the function once a button has been pressed, so it stops firing every time I press a button after the first time. (until I press the text button again)

1 answer

Log in to vote
0
Answered by 4 years ago

Found it!

I was overwriting the Value "Key" with the Value for the text. (It no longer linked to the button I wanted to change)

It was just an oversight on my part, whoops.

Ad

Answer this question