How do I prevent people from spamming E?
local userInputService = game:GetService("UserInputService") local Player = game:GetService("Players").LocalPlayer script.Parent.Equipped:connect(function() active = false end) userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessedEvent then return end if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then if active then active = true script.Parent.RemoteEvent:FireServer() wait(1) active = false else script.Parent.RemoteEvent2:FireServer() active = true Player.PlayerGui:WaitForChild("GunGUI"):Destroy() wait(1) active = false end end end end)
try this, hope you understand what i did
local userInputService = game:GetService("UserInputService") local Player = game:GetService("Players").LocalPlayer local active = false -- variable here so every function can see it script.Parent.Equipped:connect(function() active = false end) userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessedEvent then return end if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then if active == false then -- "if active then" means if active is true, now its checking if active is false active = true script.Parent.RemoteEvent:FireServer() wait(1) active = false else script.Parent.RemoteEvent2:FireServer() active = true Player.PlayerGui:WaitForChild("GunGUI"):Destroy() wait(1) active = false end end end end)
Im not entirely sure what you are trying to do, but I think it may have to do with your debounce (active).
You are saying if the function is active then make it active, so I assume your active is meant to be false.
You also have a wait, for when active becomes false which I can understand but you might want to put that somewhere else.
You also have the active set back to true everytime you do it. I believe this may work a lot better.
local userInputService = game:GetService("UserInputService") local Player = game:GetService("Players").LocalPlayer script.Parent.Equipped:connect(function() active = false end) userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessedEvent then return end if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then if not active then --If the function is active, then it will do the code below. active = true --sets it to active. script.Parent.RemoteEvent:FireServer() else --Otherwise it will run the code below if the function is active. --Please note, the function below will still be spammable, you should probably put another check in so people cant spam it. script.Parent.RemoteEvent2:FireServer() Player.PlayerGui:WaitForChild("GunGUI"):Destroy() end wait(1) --This will be how long it will wait before active is reset. active = false end end end)