Hello, I’m making a game similar to streets of rage, and right now I’m trying to add mobile support. When the player jumps, if they are moving with the thumbstick, it never sets their status to walking like it should, making the game think they are still falling. Watch the video to fully understand.
Code snippet
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").StateChanged:Connect(function(old, new)
print(tostring(old)) -- Prints to figure out why it's not working
print(tostring(new))
if new == Enum.HumanoidStateType.Freefall then
if jumpsequence.isPlaying() then
task.wait(0.3)
fallsequence.play(fps, looped)
status.Value = 6
else
fallsequence.play(fps, looped)
status.Value = 6
end
elseif new == Enum.HumanoidStateType.Landed or old == Enum.HumanoidStateType.Landed and new == Enum.HumanoidStateType.Running then
if math.round(Humanoid.MoveDirection.x) == 1 then
if spritesheet.isMirroredX() == false then
spritesheet.mirrorX()
walksequence.play(fps, looped)
status.Value = 2
end
elseif math.round(Humanoid.MoveDirection.X) == -1 then
if spritesheet.isMirroredX() == true then
spritesheet.mirrorX()
walksequence.play(fps, looped)
status.Value = 2
end
elseif math.round(Humanoid.MoveDirection.Z) == -1 or math.round(Humanoid.MoveDirection.Z) == 1 then
walksequence.play(fps, looped)
status.Value = 2
else
idlesequence.play(fps, looped)
status.Value = 4
end
end
end)
(Video’s too big so I uploaded it to google drive.)
Video:
I’ve always found when working with; Humanoid:GetPropertyChangedSignal() or Humanoid.StateChanged, adding a stepped wait() right after the trigger seems to help.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local rns = game:GetService("RunService")
Humanoid.StateChanged:Connect(function(old, new)
rns.Stepped:Wait()
--
end)
untested
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local rns = game:GetService("RunService")
Humanoid.StateChanged:Connect(function(old, new)
rns.Stepped:Wait()
local isFreefall = new == Enum.HumanoidStateType.Freefall
local isLand = new == Enum.HumanoidStateType.Landed
local isRunning = old == Enum.HumanoidStateType.Landed and
new == Enum.HumanoidStateType.Running
if isFreefall then
if jumpsequence.isPlaying() then
task.wait(0.3)
end
fallsequence.play(fps, looped)
status.Value = 6
elseif isLand or isRunning then
local dir = Humanoid.MoveDirection
local x, z = math.round(dir.X), math.round(dir.Z)
if x == 1 and not spritesheet.isMirroredX() then
spritesheet.mirrorX()
walksequence.play(fps, looped)
status.Value = 2
elseif x == -1 and spritesheet.isMirroredX() then
spritesheet.mirrorX()
walksequence.play(fps, looped)
status.Value = 2
elseif z == 1 or z == -1 then
walksequence.play(fps, looped)
status.Value = 2
else
idlesequence.play(fps, looped)
status.Value = 4
end
end
end)