I was trying to make a script that changed text of a GUI to something else after pressing "Z" button, but i could only make it do first function. How can i make it do second function after first function?
local mouse = game.Players.LocalPlayer:GetMouse() mouse.KeyDown:connect(function(key) key = key:lower() if key == "z" then One() end end) function One() script.Parent.Text = "..." end function Two() script.Parent.Text = "Test1" end function Three() script.Parent.Text = "Test2" end
I think it would be easier if you just added a wait
event between each function, or you could use a table as IdiomicLanguage stated. It's also best to use UserInputService
, as KeyDown
is deprecated.
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Z then One() wait(3) Two() wait(3) Three() end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
More information here. If this helped, please accept answer! Thanks!
This is a little bit more powerful than you are asking for, but perhaps it will be a learning experience for you:
local curFunc = 0 local funcOptions = { function () script.Parent.Text = "..." end; function () script.Parent.Text = "Test1" end; function () script.Parent.Text = "Test2" end; } local function onMouseKeyDown(key) if key:lower() == "z" then curFunc = (curFunc % #funcOptions) + 1 funcOptions[curFunc]() end end) local mouse = game.Players.LocalPlayer:GetMouse() mouse.KeyDown:Connect(onMouseKeyDown)