Is it possible to keep a player from moving on a certain axis?
My first ROBLOX game is going to be 2D, so I only want the player to use A and D to move and use W to jump and S to crouch, so W and S still have to be useable. I'm not sure if it's necessary, but here's my local script for jumping:
04 | local player = game.Players.LocalPlayer |
05 | local character = player.Character or player.CharacterAdded:Wait() |
06 | local humanoid = character:WaitForChild( "Humanoid" ) |
07 | local mouse = player:GetMouse() |
09 | local jumpEvent = game:GetService( "ReplicatedStorage" ):WaitForChild( "jumpEvent" ) |
11 | mouse.KeyDown:Connect( function (key) |
12 | if string.lower(key) = = "w" then |
13 | jumpEvent:FireServer() |
and here's my server script:
2 | local jumpEvent = Instance.new( "RemoteEvent" , game:GetService( "ReplicatedStorage" )) |
3 | jumpEvent.Name = "jumpEvent" |
4 | jumpEvent.OnServerEvent:Connect( function (player) |
6 | player.Character.Humanoid.Jump = true |
I've tried to change the property in StarterPlayer to scriptable and add each control individually, but I can't figure out what event to use that makes you walk in a certain direction because most of them are used to teleport the player. Also, I'm not sure how to make the player continue walking when holding the button down.
Here's what I tried in my local script for moving right:
04 | local player = game.Players.LocalPlayer |
05 | local character = player.Character or player.CharacterAdded:Wait() |
06 | local humanoid = character:WaitForChild( "Humanoid" ) |
07 | local mouse = player:GetMouse() |
09 | local moveRight = game:GetService( "ReplicatedStorage" ):WaitForChild( "moveRight" ) |
11 | mouse.KeyDown:Connect( function (key) |
12 | if string.lower(key) = = "d" then |
13 | moveRight:FireServer() |
I've also tried to change the if then part to a while loop but that just loops the action forever.
Here's the server script:
2 | local moveRight = Instance.new( "RemoteEvent" , game:GetService( "ReplicatedStorage" )) |
3 | moveRight.Name = "moveRight" |
4 | moveRight.OnServerEvent:Connect( function (player) |
6 | player.Character.Humanoid:Move(Vector 3. new( 0 , 16 , 0 ), true ) |
The move right scripts doesn't seem to do anything, but I can't think of anything else that would work.
I hope that you guys can help! Thanks!