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

How would you make a key press filtering enabled?

Asked by 6 years ago
Edited 6 years ago
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

0
I have tried using remote events I still has to functionality carsheep -8 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
Ad

Answer this question