Why is input mixed with the key to trigger?

I have this tool for emotes, theres 2 functions
the userinput.keycode = to the trigger to pick the emotes
the lkey = the bind to pick the emote as a shortcut

instead of them doing what they are supposed to do, they have swapped places, its like the lkey is now the trigger to pick the emote and the input is the bind for the emote

heres my code:

local Equipped = false
local Player = game.Players.LocalPlayer
local LKey = ""
local Mouse = Player:GetMouse()

Mouse.KeyDown:Connect(function(key)
	if key == "t" then
		LKey = key
	end
end)

script.Parent.Equipped:Connect(function(m)
	Equipped = true
end)
script.Parent.Unequipped:Connect(function(m)
	Equipped = false
end)

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local CRl = Instance.new('Animation')
CRl.AnimationId = "rbxassetid://14647316084"
local Track = animator:LoadAnimation(CRl)

local Data = Player:WaitForChild("Keybinds"):WaitForChild("Extras"):WaitForChild("OpenEmotes")
local GUI = Player.PlayerGui:WaitForChild("Start"):WaitForChild("Extras"):FindFirstChild("CelebrationGUI")
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.G then
		if LKey== "t" then
			Track:Play()
		end
	end
end)

Mouse.KeyUp:Connect(function(key)
	if key == "p" then
		for i,v in pairs(humanoid:GetPlayingAnimationTracks()) do
			v:Stop()
		end
		LKey = ""
	end
end)

2 Likes