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

How to prevent people from spamming "E"?

Asked by 4 years ago

How do I prevent people from spamming E?

01local userInputService = game:GetService("UserInputService")
02local Player = game:GetService("Players").LocalPlayer
03 
04script.Parent.Equipped:connect(function()
05    active = false
06end)
07 
08userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
09    if gameProcessedEvent then return end
10    if input.UserInputType == Enum.UserInputType.Keyboard then
11        if input.KeyCode == Enum.KeyCode.E then
12            if active then
13                active = true
14                script.Parent.RemoteEvent:FireServer()
15 
View all 27 lines...
0
have you tried making the wait() longer? Struggage 10 — 4y
0
Use a Server-sided Cooldown Hashmap on the OnServerEvent signal. Ziffixture 6913 — 4y
0
Struggage wait() is not a problem, because 1 second does take a while. TheBuliderMC 84 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

try this, hope you understand what i did

01local userInputService = game:GetService("UserInputService")
02local Player = game:GetService("Players").LocalPlayer
03local active = false -- variable here so every function can see it
04 
05script.Parent.Equipped:connect(function()
06    active = false
07end)
08 
09userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
10    if gameProcessedEvent then return end
11    if input.UserInputType == Enum.UserInputType.Keyboard then
12        if input.KeyCode == Enum.KeyCode.E then
13            if active == false then -- "if active then" means if active is true, now its checking if active is false
14                active = true
15                script.Parent.RemoteEvent:FireServer()
View all 28 lines...
0
Doesn't work, I can still spam E on it. TheBuliderMC 84 — 4y
0
ohh i know why jerryisgod29 176 — 4y
0
so you want to fire RemoteEvent2 and destroy gui after what? if player presses wrong number? jerryisgod29 176 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

01local userInputService = game:GetService("UserInputService")
02local Player = game:GetService("Players").LocalPlayer
03 
04script.Parent.Equipped:connect(function()
05    active = false
06end)
07 
08userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
09    if gameProcessedEvent then return end
10    if input.UserInputType == Enum.UserInputType.Keyboard then
11        if input.KeyCode == Enum.KeyCode.E then
12            if not active then --If the function is active, then it will do the code below.
13                active = true --sets it to active.
14                script.Parent.RemoteEvent:FireServer()
15            else --Otherwise it will run the code below if the function is active.
View all 25 lines...

Answer this question