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

For some reason it changes the background of the frame no matter what key is pressed?

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D then
        player.PlayerGui.Pressed.Frame.BackgroundColor3 = Color3.fromRGB(16, 255, 16)
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D then
        player.PlayerGui.Pressed.Frame.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
    end
end)

how do I make it so it only changes the background when these keys are pressed because for some reason it changes it no matter what key is pressed.

1 answer

✓ Accepted answer

It's because when you put in this line:

if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.A or Enum.KeyCode.S or Enum.KeyCode.D then

You said:

or Enum.KeyCode.(Whatever Key)

instead put

or input.KeyCode == Enum.KeyCode.(Whatever Key)

I'm honestly not sure why this happens when you only put "Or Enum.KeyCode.(Whatever Key)" but this should fix your issue, just a bit longer code.

1 comment

0

Thaks a lot for helping :D

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