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

My Keybind TextLabel Script Won't Work. Help please?

Asked by
Aqu_ia 39
5 years ago
local textlabel = game.StarterGui.ScreenGui.TextLabel
game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(KeyPressed)

if KeyPressed == "g" then

if game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text == "Shii-Cho" then

game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = "Makashi"
else
game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = "Shii-Cho"
if game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text == "Makashi" then

game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Text = "Soresu"

            end
        end
    end
end)
0
When I first pressed G, it only switches to Makashi, but when I press G again, it switches back to shii-cho, and not to soresu. Aqu_ia 39 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Take a different approach. UserInputService is more appropriate.

label = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel
game:GetService("UserInputService").InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.G then
    if label.Text == "Shii-Cho" then
        label.Text = "Makashi"
    elseif label.Text = "Makashi" then
        label.Text = "Soresu"
    else
        label.Text = "Shii-Cho"
end)
Ad

Answer this question