I reinvented the wheel for movement on Roblox

legend says it never could be done

local ContextActionService,w,a,s,d = game:GetService('ContextActionService'),0,0,0,0

ContextActionService:BindAction('w', function()
	w = math.abs(w - 1)
end, false,'w')

ContextActionService:BindAction('a', function()
	a = math.abs(a - 1)
end, false,'a')

ContextActionService:BindAction('s', function()
	s = math.abs(s - 1)
end, false,'s')

ContextActionService:BindAction('d', function()
	d = math.abs(d - 1)
end, false,'d')

local RunService,Player = game:GetService('RunService'), game:GetService('Players').LocalPlayer

RunService:BindToRenderStep('𝄴',100, function()	
	
	local WASD = Vector3.new(d - a, 0, s - w)
	
	Player:Move(WASD,true)
	
end)

bruh i gave the wrong code

this is now the right code

5 Likes

You forgot jumping. :shallow_pan_of_food:

i didnt want jump so i didnt add it in

Ok, i recently did something like this too to make the player constantly follow the mouse when the left button is pressed, works better than i thought for some games.

nice!

i made this script to see if i could make something simple but without using if statements at all

cuz i saw a post about guy talking about how he avoids ifs statements if he can and i think he gave some pretty good reasons for it

this is what my script looked like before

game:GetService('ContextActionService'):BindAction(' ', function(string,state,input)

  if state == Enum.UserInputState.Begin then

    if input.KeyCode == Enum.KeyCode.W then
      w = 1
    elseif input.KeyCode == Enum.KeyCode.A then
      a = 1
    elseif input.KeyCode == Enum.KeyCode.S then
      s = 1
    elseif input.KeyCode == Enum.KeyCode.D then
      d = 1
    end

  elseif state == Enum.UserInputState.End then

    if input.KeyCode == Enum.KeyCode.W then
      w = 0
    elseif input.KeyCode == Enum.KeyCode.A then
      a = 0
    elseif input.KeyCode == Enum.KeyCode.S then
      s = 0
    elseif input.KeyCode == Enum.KeyCode.D then
      d = 0
    end

  end

end,false,'w','a','s','d')

game:GetService('RunService'):BindToRenderStep(" ", 100, function()
  Player:Move(Vector3.new(a-d,0,w-s), true)
end)
1 Like