hi, so im making a 2D-esque game and for best experience, i want to make it so that you can only move left and right, rather than just putting invisible walls around the map. i sunk the forwardmovement and backwardmovement playeractions, but i dont know how to make this work for mobile. so, i am making a custom movement system specifically for mobile players, and i only have the left button scripted so far, but theres a problem. humanoid:move() seems to make the players movement very choppy and jittery. i tried setting the networkowner of the games parts to nil, but while that fixed the problem, it caused a ton of delay for all devices. is there anything else i can use rather than humanoid:move()? or, is there a way to fix this choppy movement whilst using humanoid:move()? please help
local leftMovementEvent = game.ReplicatedStorage.MobileMovement.LeftMovementEvent
local leftMovementEvent2 = game.ReplicatedStorage.MobileMovement.LeftMovementEvent2
if game:GetService("UserInputService").TouchEnabled == true then
player.PlayerGui.TouchGui.TouchControlFrame.Size = UDim2.new(0, 0, 0, 0)
player.PlayerGui.TouchGui.TouchControlFrame.Position = UDim2.new(-100, 0, 0, 0)
player.PlayerGui.Screens.MobileMovementFrame.Visible = true
player.PlayerGui.Screens.MobileJumpButtonFrame.Visible = true
player.PlayerScripts.PlayerModule.ControlModule:Destroy()
local aButton = player.PlayerGui.Screens.MobileMovementFrame.AButton
local dButton = aButton.Parent.DButton
local jumpButton = player.PlayerGui.Screens.MobileJumpButtonFrame.JumpButton
aButton.InputBegan:Connect(function(input)
if true and input.UserInputType == Enum.UserInputType.Touch then
leftMovementEvent:FireServer(true)
aButton.InputEnded:Connect(function(input)
if true and input.UserInputType == Enum.UserInputType.Touch then
leftMovementEvent2:FireServer(true)
end
end)
end
end)
end
server
local movementEvent = game.ReplicatedStorage.MobileMovement.LeftMovementEvent
local movementEvent2 = game.ReplicatedStorage.MobileMovement.LeftMovementEvent2
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
movementEvent.OnServerEvent:Connect(function()
if true then
local leftMovementEnabled = true
movementEvent2.OnServerEvent:Connect(function()
if true then
leftMovementEnabled = false
end
end)
while task.wait(0.000001) do
humanoid:Move(Vector3.new(-1, 0, 0), false)
if leftMovementEnabled == false then break end
end
end
end)
end)
end)
keep in mind that im a beginner scripter, so the code is probably very unethical and messy
i tried that before using move(), but no matter what number i put in the vector3, the character would always stop moving at some point, even if the referenced point was far away from the map
edit: nvm reread your message, i tried it on the server, will try on the client
The movement is very shaky, but it reaches its destination in a very inefficient matter
This can be fixed by using :SetNetworkOwner()
Roblox will automatically set the network owner to the client when there are unanchored parts in near proximity. You DONT want this when handling NPC movement. This can be fixed by doing:
plr.Character:SetNetworkOwner(nil)
Note: This is most likely not the issue as you are moving the player’s character
It keeps stopping mid way
This is because you keep rapidly calling :MoveTo()
Yield until it is done by doing:
humanoid:Move(Vector3.new(-1,0,0), false)
humanoid.MoveToFinished:Wait() --this line yields the code until the humanoid has finished moving to the destination
instead of:
while task.wait(0.000001) do
humanoid:Move(Vector3.new(-1, 0, 0), false)
“If you need an obscenely long decimal, you’re are doing it wrong”
the first one is the one that is happening, but i already tried your solution and it just caused more problems. i tried the second one but it just makes the character move one stud at a time
fixed it by setting the networkowner to nil only when the player presses the button, and setting it back to the server whenever the player lets go. there is a little bit of delay, but its not too obstructive