Why does this script execute one "step" behind?
For some reason, my script always executes these "steps" one step behind on Mobile devices. And idea on why this might be happening? I posted relevant coding below. Thanks!
01 | repeat wait() until game.Players.LocalPlayer.Character ~ = nil |
03 | currentcell = game.ReplicatedStorage.Move:InvokeServer() |
04 | mouse = game.Players.LocalPlayer:GetMouse() |
11 | if game:GetService( "UserInputService" ).KeyboardEnabled = = true then |
14 | if game:GetService( "UserInputService" ).TouchEnabled = = true then |
22 | game:GetService( "UserInputService" ).TouchStarted:connect( function () |
23 | if active = = false and mouse.Hit and ((mouse.Hit.p-currentcell.PrimaryPart.Position).magnitude < = 15 and (mouse.Hit.p-currentcell.PrimaryPart.Position).magnitude > = 5 ) then |
25 | local mouspos = mouse.Hit.p |
26 | local ray = Ray.new(currentcell.PrimaryPart.Position,((mouspos-currentcell.PrimaryPart.Position).unit* 10 )*Vector 3. new( 1 , 0 , 1 )) |
27 | local part = game.Workspace:FindPartOnRayWithIgnoreList(ray, { game.Players.LocalPlayer.Character,currentcell } ) |
28 | if part ~ = nil and part.Parent ~ = nil and part.Parent.Name = = "FloorCell" and (currentcell.PrimaryPart.Position-part.Parent.PrimaryPart.Position).magnitude = = 10 then |
29 | currentcell = part.Parent |
31 | game.Players.LocalPlayer.Character.Humanoid:MoveTo(Vector 3. new(part.Position.X,part.Position.Y+ 5 ,part.Position.Z)) |
34 | game.Players.LocalPlayer.Character.Humanoid.MoveToFinished:connect( function () |
35 | game.Players.LocalPlayer.Character.Torso.Velocity = Vector 3. new( 0 , 0 , 0 ) |