Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

1 comment

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.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.