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

Why script turn on when I press E in chat?

How I make it so when I press E in chat nothing happens cuz it's annoying (my english bad sory)

wait(1)

local UserInputService = game:GetService("UserInputService")
local KunaiValue = game.Players.LocalPlayer.Backpack.KunaiValue
local ExplosiveKunaiValue = game.Players.LocalPlayer.Backpack.ExplosiveKunaiValue
local WhichKunai = game.Players.LocalPlayer.Backpack.WhichKunai
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Cooldown = false 
local ExplosiveCooldown = false
local KeyHeld = false
local HasKunai = false 
local CDTime = .4 
local EPTime = 2
local KunaiAmount = 0
local Delay = .7 

function onKeyPress(inputObject,gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.E then
		if WhichKunai.Value == "Kunai" then 
			
		if KunaiValue.Value == 0 then return end 
		if Cooldown then return end 

		spawn(function()
			Cooldown = true
			wait(CDTime)
			Cooldown = false 
		end)
		
        KeyHeld = true
		script.KeyHeld:FireServer(Player)
		
        while KeyHeld do
			if KunaiAmount >= 5 then return end 
			if KunaiValue.Value == 0 then return end 
			HasKunai = true
            KunaiAmount = KunaiAmount + 1 
			KunaiValue.Value = KunaiValue.Value - 1  
			script.SoundEvent:FireServer(Player, KunaiAmount, Mouse)
			wait(Delay)
				
        	end
		end 
	end
end

function onExplosive(inputObject,gameProcessed)
	if inputObject.KeyCode == Enum.KeyCode.E then
		if ExplosiveCooldown then return end 
		
		spawn(function()
			ExplosiveCooldown = true
			wait(EPTime)
			ExplosiveCooldown = false 
		end)
		
		if WhichKunai.Value == "ExplosiveKunai" then 
			if ExplosiveKunaiValue.Value == 0 then return end 
			print("Shooting explosive kunai..sause!")
			ExplosiveKunaiValue.Value = ExplosiveKunaiValue.Value - 1
			script.ExplosiveKunai:FireServer(Mouse.Hit)
		end
	end
end

function onKeyRelease(inputObject,gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.E then
		if HasKunai == false then return end 
		script.KeyRelease:FireServer(KunaiAmount, Mouse.Hit)
		KunaiAmount = 0 
		KeyHeld = false
		HasKunai = false 
    end
end

UserInputService.InputBegan:connect(onKeyPress)
UserInputService.InputEnded:connect(onKeyRelease)
UserInputService.InputBegan:connect(onExplosive)

https://gyazo.com/4f6f9e76a1917922742c607f34e7afa3

2 comments

0

because you have gameProcessedEvent. yet you're not using it in your script

0

whats that

1 answer

You need a second argument in the UIS, called the "GameProcessedEvent", this makes sure that the key "E" will not work when in chat, after you write the onkey funciton then write an if statement, that can only be passed with the game processed event, hope this helped somewhat.

Happy Coding, Destroyer1234x

2 comments

0

script ?

0

I don't provide free scripts, I only give advice and help.

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