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.