I have a script that should alternate between the visibility of two guis when walking, and enable the visibility of one when standing still, to make a 2d animation of walking. However, the method im using to detect player movement can cause the guis to flicker rapidly whenever there is a change in movement magnitude. how can i make the script work so that the function is connected whenever the character is moving instead of whenever the players magnitude changes? Everything else in the script works except for this.
my code (in a localscript under starterplayerscripts)
local plr = game:GetService("Players").LocalPlayer
local player = plr.Character or plr.CharacterAdded:Wait()
local hum = player:WaitForChild("Humanoid")
local gui = plr.PlayerGui
local neu = gui.gamescreen.armsidle
local one = gui.gamescreen.armsmove1
local two = gui.gamescreen.armsmove2
local armscheck = 0
local magncheck = 0
print("check")
hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if hum.MoveDirection.Magnitude > 0 then
magncheck = 1
while magncheck == 1 do
if armscheck == 0 then
one.Visible = true
neu.Visible = false
two.Visible = false
armscheck = 1
elseif armscheck == 1 then
one.Visible = false
neu.Visible = false
two.Visible = true
armscheck = 0
else
return
end
wait(0.2)
end
end
if hum.MoveDirection.Magnitude == 0 then
magncheck = 0
end
end)
hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
one.Visible = false
neu.Visible = true
two.Visible = false
end)