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

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

Asked by 7 years ago

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

Log in to vote
3
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

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)
0
thanks! :D XxJRushxX 22 — 7y
0
Dang, you beat me to it. I was about to say the same thing ;~; OrcaTheFish 95 — 7y
Ad

Answer this question