Need help with 2d sprite animation script invisible glitching kind of effect thingy

does anyone know how to fix this glitch thingy
I tried searching for some solution but nothing helps
so if anyone does know how to fix please help

local char = script.Parent
local sprite = game.StarterGui.Sprite:Clone()
sprite.Adornee = char.HumanoidRootPart
sprite.Parent = char.HumanoidRootPart
local hum = char.Humanoid
local InputService = game:GetService("UserInputService")

local isIdle = true 
local isRunning = false
local isFalling = false

local function Flip()
	sprite.ImageLabel.ImageRectSize = Vector2.new(-1024,1024)
	sprite.ImageLabel.ImageRectOffset = Vector2.new(1024, 0)
end

local function UnFlip()
	sprite.ImageLabel.ImageRectSize = Vector2.new(0,0)
	sprite.ImageLabel.ImageRectOffset = Vector2.new(0, 0)
end

InputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A then
		Flip()
	elseif key.KeyCode == Enum.KeyCode.D then
		UnFlip()
	end
end)

local function Fall()
	while isFalling do
		sprite.ImageLabel.Image = "rbxassetid://16644920016"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644919781"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644919543"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644919321"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644919068"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644918906"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644918906"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644918548"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644918375"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644918129"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644917843"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644917718"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644917587"
		wait(.01)
	end
end

local function Jump()
	sprite.ImageLabel.Image = "rbxassetid://16644871216"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644871216"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644870714"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644870393"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644870148"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644870148"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644870148"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644869500"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644869170"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644868948"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644868802"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644868615"
end

local function Run()
	while isRunning do
		sprite.ImageLabel.Image = "rbxassetid://16644691231"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644691072"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644690824"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644690639"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644690436"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644690214"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644689920"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644689693"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644689471"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644689191"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644688858"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644688515"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644688315"
		wait(.01)
	end
end

local function PreRun()
	sprite.ImageLabel.Image = "rbxassetid://16644648238"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644648093"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644647878"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644647661"
	wait(.01)
	sprite.ImageLabel.Image = "rbxassetid://16644647423"
end

local function Idle()
	while isIdle do
		sprite.ImageLabel.Image = "rbxassetid://16644089962"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644209832"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644209461"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644209092"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644276222"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644275981"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644275696"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644275563"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644275448"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644275290"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644274941"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644274773"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644274554"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644274350"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644274170"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644274012"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644273843"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644273602"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644273379"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644273123"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644272936"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644272673"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644272542"
		wait(.01)
		sprite.ImageLabel.Image = "rbxassetid://16644272317"
		wait(.01)
	end
end



hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if hum.MoveDirection.Magnitude > 0 then
		isIdle = false  
		isRunning = true
		isFalling = false
		PreRun()
		wait(.06)
		Run()
	else
		isFalling = false
		isRunning = false
		isIdle = true   
		Idle()          
	end
end)


hum.Jumping:Connect(function()
	Jump()

end)

hum.StateChanged:Connect(function(state)
	if state == Enum.HumanoidStateType.FallingDown then
		isFalling = true
		Fall()
		isRunning = false
		isIdle = false
	end
end)

Idle()
3 Likes

So if I were you I would keep only one image which I know works in case there are any faulty ones, just try that

1 Like

I played around with the script.

I was not able to fix the problem, but I was able to figure where it seems to be coming from.

Here is my file:
Sprite.rbxl (57.3 KB)

The problem seems to be caused by using GetPropertyChangedSignal(“MoveDirection”).

Maybe there is another way to check if the player is moving.

Or just check if they are pressing a button/key:

2 Likes

i tried doing input check but still has the same problem and I tried using hum.Changed still have same problem and tried adding more sprites/images for Idle,PreRun,Run,Jump,Fall still didn’t work not sure whats causing the issue but ill guess that every frame are overlapping with each other maybe

Did you download the Sprite.rbxl file I posted above?

There is only Running in it. You can see using GetPropertyChangedSignal(“MoveDirection”) is causing the problem.

Listening for key/button input should be more consistent and may remove the glitch.

InputService.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.D then
		isRunning = true
		isIdle = false
		Run()
	end
end)

InputService.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.D then
		isRunning = false
		isIdle = true
		Idle()
	end
end)

i added this and it still has the same problem

There appears to be a glitch in the sequence of images.

I played the following cycle of images and it turns on and off with just the images playing:

local RunningCoroutine = coroutine.wrap(function()
	while task.wait() do
		Running_ImageLabel.Image = "rbxassetid://16644691231"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644691072"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644690824"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644690639"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644690436"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644690214"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644689920"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644689693"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644689471"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644689191"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644688858"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644688515"
		wait(Time)
		Running_ImageLabel.Image = "rbxassetid://16644688315"
		wait(Time)
	end
end)
RunningCoroutine()