I've been having trouble getting my FilteringEnabled scripts to work lately. This mostly includes bugs such as too many objects being created or values being made out of sync. These errors mostly result from the client spamming UserInput.

I've tried adding debounces, buffers, delays, etc., but no matter how many methods I use, the client is still able to cause something abnormal to happen, that shouldn't.

It doesn't necessarily break the game, since most people won't be spamming their keyboard, but with enough dedication, it's not difficult to break certain aspects of the game.

My LocalScript relies a lot on the server sending back the correct value, and even waits before returning these values (as a bit of a buffer) but still, my part variable is sometimes incorrectly nil. Here's my UserInput code, which I find to be most responsible. My main issue is often when spam sending the server part at line 15, it's nil, when it should be a part in a Workspace Folder, as defined in line 7.

UserInput.InputBegan:Connect(function(input, ignore)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Key and using == false then
			for i = 1, #parts do
				local magnitude = (char.Humanoid.RootPart.Position - parts[i].Position).Magnitude
				if magnitude <= range then
					buffer, part = use:InvokeServer(parts[i], char) --part returns the part used
					if buffer == true then
						wait(.5)
						using = true
					end
				end
			end
		elseif input.KeyCode == Key or input.KeyCode == Enum.KeyCode.Space and using == true then
			buffer, part = stopuse:InvokeServer(part, char) --returns part as nil.
			if buffer == false then
				wait(.5)
				using = false
			end
		end
	end
end)

I believe that my best solution is to add waits to parts of the UserInput, but I do not know the appropriate places to put these waits.

3 comments

0

If it's a problem of spamming a button, the best way I can think of is using debounce

0

I tried using a debounce in different places, but somehow it can still end up breaking. I'm not quite sure where to even put the debounce, since nowhere I put it seems to work.

0

What are you trying to achieve? I feel like there is a better method than invoking the server. You have to prevent the player from using InvokeServer, maybe you are using debounces wrong?