How do I prevent people from spamming E?
01 | local userInputService = game:GetService( "UserInputService" ) |
02 | local Player = game:GetService( "Players" ).LocalPlayer |
03 |
04 | script.Parent.Equipped:connect( function () |
05 | active = false |
06 | end ) |
07 |
08 | userInputService.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 |
try this, hope you understand what i did
01 | local userInputService = game:GetService( "UserInputService" ) |
02 | local Player = game:GetService( "Players" ).LocalPlayer |
03 | local active = false -- variable here so every function can see it |
04 |
05 | script.Parent.Equipped:connect( function () |
06 | active = false |
07 | end ) |
08 |
09 | userInputService.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() |
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.
01 | local userInputService = game:GetService( "UserInputService" ) |
02 | local Player = game:GetService( "Players" ).LocalPlayer |
03 |
04 | script.Parent.Equipped:connect( function () |
05 | active = false |
06 | end ) |
07 |
08 | userInputService.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. |