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, your controls are reversed. So when you press w to walk forward, you go back and also on mobile. 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 and such.
local function reverseControls(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local userInputService = game:GetService("UserInputService")
local function onInput(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
humanoid:Move(Vector3.new(0, 0, -1))
elseif input.KeyCode == Enum.KeyCode.S then
humanoid:Move(Vector3.new(0, 0, 1))
elseif input.KeyCode == Enum.KeyCode.A then
humanoid:Move(Vector3.new(1, 0, 0))
elseif input.KeyCode == Enum.KeyCode.D then
humanoid:Move(Vector3.new(-1, 0, 0))
end
elseif input.UserInputType == Enum.UserInputType.Touch then
-- Reverse mobile joystick controls
if input.Position.X < (game:GetService("GuiService"):GetScreenResolution().X / 2) then
humanoid:Move(Vector3.new(-input.Delta.Position.X, 0, 0))
else
humanoid:Move(Vector3.new(0, 0, -input.Delta.Position.X))
end
end
end
userInputService.InputBegan:Connect(onInput)
end)
end
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
reverseControls(player)
end
game:GetService("Players").PlayerAdded:Connect(reverseControls)
I put this in a 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.