System that changes your controls randomly

Hi! I am a new roblox programmer and developer and i am trying to make my first real game. I decided to make it an obby but with a twist, every like 10 or 30 seconds your controls changes randomly. So when you press w to walk forward, you go right instead and you can like have a gui at the top of the screen that shows how long it is until the controls changes and what the current controls are. But because i am a new developer i struggled with making a script that changes the controls.

Here is my try with the limited knowledge i have from youtube videos.

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local function RandomizeControls(player)
    local controls = {
        ["w"] = "s", ["a"] = "d", ["s"] = "w", ["d"] = "a",
        ["up"] = "down", ["down"] = "up", ["left"] = "right", ["right"] = "left",
        ["q"] = "e", ["e"] = "q", ["z"] = "x", ["x"] = "z"

    }

    local function ChangeControl(input)
        return controls[input] or input
    end

    local function OnInputBegan(input, gameProcessedEvent)
        if not gameProcessedEvent then
            local newKeyCode = ChangeControl(input.KeyCode.Name)
            UserInputService.InputBegan:Fire({ KeyCode = Enum.KeyCode[newKeyCode] })
        end
    end

    UserInputService.InputBegan:Connect(OnInputBegan)

    while true do
        wait(10) 
        controls = {
            ["w"] = "s", ["a"] = "d", ["s"] = "w", ["d"] = "a",
            ["up"] = "down", ["down"] = "up", ["left"] = "right", ["right"] = "left",
            ["q"] = "e", ["e"] = "q", ["z"] = "x", ["x"] = "z"

        }
    end
end

Players.PlayerAdded:Connect(function(player)
    RandomizeControls(player)
end)

I put this in a normal script inside ServerScriptService

I don’t know if this is close or if im completely wrong.

If you help me i will give you credits in the description as a thanks.

1 Like

??? i dont get the question.
have you checked if the script works?

I’m sorry if i wasn’t clear before, i am making an obby game with a twist. The twist is that every 10 seconds your controls changes, so the normal controls are obviously W = forward, A = left, S = back and D = right, but every 10 seconds it changes so it maybe is like W = right, A = back, S = left and D = forward. I tried to make it with the script in my previous message but i am a new programmer so i am not that good. I hope this clarifies what i was trying to say and that you understand me this time. Thank you for your time :slight_smile: