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

How would you make a key press filtering enabled?

local m = game.Players.LocalPlayer:GetMouse()
db = true
m.KeyDown:connect(function(k)
	k = k:lower()
	if k == "f" then
		if script.parent.FlapSetting.Value <= 2 then
		script.parent.FlapSetting.Value = script.parent.FlapSetting.Value + 1
		end
	end
end)

This works flawlessly without FE enabled but has no function whatsoever when I enabled it. It is in a local script

2 comments

0

I have tried using remote events I still has to functionality

1 answer

✓ Accepted answer

Do something like when the player presses a key on a LocalScript, it fires a remote event that the server sided script picks up. The server will do all the changing values and stuff.

Here's an example.

Note: I used UserInputService as Roblox says the mouse keydown function is deprecated. Basically, they recommend using this one.

LocalScript

game:GetService("UserInputService").InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.F then
		script.Parent.RemoteEvent:FireServer() -- RemoteFunction can be anywhere, as long as the server script knows where it is.
	end
end)

Script

script.Parent.RemoteEvent.OnServerEvent:connect(function(plr)
	--The first argument in an OnServerEvent is the player who fired the RemoteEvent.

	--Code here, this will be in a server script so everyone see's the change.
end)

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