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

When I'm typing in chat, whenever I press E I punch. Any Tips?

So I'm coding a zombie apocalypse game. and whenever I type in chat pressing "E" makes me punch. Anybody got something to help?

This is a LocalScript.

wait(1)
local InputS = game:GetService("UserInputService")
local PunchLeft = Instance.new("Animation")
PunchLeft.AnimationId = "rbxassetid://860764666"
local PunchRight = Instance.new("Animation")
PunchRight.AnimationId = "rbxassetid://860750433"
local plr = game.Players.LocalPlayer
local WooshSound = Instance.new("Sound")
WooshSound.SoundId = "rbxasset://sounds//swordslash.wav"
WooshSound.Pitch = 1.95
WooshSound.TimePosition = 0.4
local HitSound = Instance.new("Sound")
HitSound.SoundId = "rbxassetid://367499850"
WooshSound.Parent = plr.Character.Torso
HitSound.Parent = plr.Character.Torso
local mouse = plr:GetMouse()
local t = 1
local debounce = true
local attack = false
function Tag(hit)
	local tag = Instance.new("BoolValue")
	local tag2 = Instance.new("BoolValue")
	local remover = script.TagRemoval:clone()
	local remover2 = script.TagRemoval:clone()
	tag.Parent = hit
	tag2.Parent = hit
	remover.Parent = tag
	remover.Disabled = false
	remover2.Parent = tag2
	remover2.Disabled = false
	tag.Name = "HitTag"
	tag2.Name = "StunTag"
	hit.PlatformStand = true
end
InputS.InputBegan:connect(function(key)
	local human = plr.Character:FindFirstChild("Humanoid")
	local tool = plr.Character:FindFirstChildOfClass("Tool")
	if key.KeyCode == Enum.KeyCode.E and plr.Backpack.Stamina.Value >= 10 then
		print('punch')
		if t == 1 and debounce and human and tool == nil and human.PlatformStand == false then
			debounce = false
			attack = true
			local T0 = human:LoadAnimation(PunchRight)
			T0:Play()
			WooshSound:Play()
			plr.Backpack.UseStam:Fire(10)
			T0.KeyframeReached:connect(function(key)
				if key == "contact" then
					plr.Character["Right Arm"].Touched:connect(function(hit)
						local ehuman = hit.Parent:FindFirstChild("Humanoid")
						if attack and ehuman then
							local tag = ehuman:FindFirstChild("HitTag")
							if tag == nil then
							HitSound:Play()
							attack = false
							ehuman.PlayerTag.Value = plr.Name
							ehuman:TakeDamage(10)
							Tag(ehuman)
							end
							end
					end)
				end
			end)
			T0.Stopped:connect(function()
				debounce = true
				attack = false
				t = 2
			end)
		end
				if t == 2 and debounce and human and tool == nil and human.PlatformStand == false then
			debounce = false
			attack = true
			local T1 = human:LoadAnimation(PunchLeft)
			T1:Play()
			WooshSound:Play()
			plr.Backpack.UseStam:Fire(10)
			T1.KeyframeReached:connect(function(key)
				if key == "contact" then
					plr.Character["Left Arm"].Touched:connect(function(hit)
						local ehuman = hit.Parent:FindFirstChild("Humanoid")
						if attack and ehuman then
							local tag = ehuman:FindFirstChild("HitTag")
							if tag == nil then
							HitSound:Play()
							attack = false
							ehuman.PlayerTag.Value = plr.Name
							ehuman:TakeDamage(10)
							Tag(ehuman)
							end
							end
					end)
				end
			end)
			T1.Stopped:connect(function()
				debounce = true
				attack = false
				t = 1
			end)
		end
	end
end)

1 answer

✓ Accepted answer

There's another parameter for InputBegan that does this. It's called gameProcessedEvent. If it's true, then that means the input began on top of a gui object (like the chat)

uis.InputBegan:connect(function(input, gpe)
	if not gpe then
		print("he wasn't chatting")
	end
end)

2 comments

0

thanks! :D

0

Dang, you beat me to it. I was about to say the same thing ;~;

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