Need help with scripting an animation with sprite sheets

And theres a lot of animations for characters.

Plus, it would be really time consuming since every sprite sheet im using has more than 30 sprites.

I did something similar to this with GIFs and SurfaceGUI, my friend showed me this handy script. You could most likely modify this to work for your case. I like this one in particular because you can control the FPS. It’s set up where you can have multiple GIFs on a screen, and switch them with a command. To convert your GIFs into a sprite sheet, you can use this if you need to.

Note: You can ignore the plr = owner stuff, that’s because it was made to work on a special case.

1 Like

You could do something like this, though it is very inefficient.

while true do
wait()
	script.Parent.ImageRectOffset = Vector2.new(240,240)
	for i = 1,4 do
		wait(1)

	script.Parent.ImageRectOffset = Vector2.new(script.Parent.ImageRectOffset.X+240,240)
	end
end

You will need to change the image size and offset too.
Change the vector2 values to whatever flips to the next frame.

Thanks! Since the spritesheets are really big I can just seperate each of them for each animation.
Example (yes im using fnf/friday night funkin’ spritesheets):

Watch out though, I don’t think some of those sprites are Roblox friendly!

1 Like

Yeah I know, I already have the open source game files, so I can open adobe animate and edit the animations from there.

1 Like

Is there a site where I can find the fps for the spritesheet im using? The spritesheet im using isnt mine and is taken from a game outside of roblox, so I dont know the fps of it.

The FPS doesn’t have to be the same as the GIF. I don’t know much about FNF, but the animations are probably 30 FPS, to keep traditional with flash games. If that doesn’t look right, you can just play around with it until it looks good.

1 Like

Thanks for the script! If I can’t find a way to make it work with a screen gui then I’ll tell you.

No problem! I’ll let my friend know it helped you.

1 Like

I have a question, how would I make it so for the idle animation it starts at the frame i want it to instead of the first frame? Since the first frame is for another animation thats not the idle animation.

Also, what is the setup_gif() for?
Nevermind, I found out.

You could maybe set the currentFrame to the start of the idle animation, but you’d have to do some code logic yourself for that. If you’d want to do it multiple times, you could add a new option called startingFrame or something, so you wouldn’t have to specify it for each gif that needs it.

Ok, So, Its showing the image but it isnt looping through the frames

Heres my edit:

local img = script.Parent

local gifs = {
	['bf_menu_idle'] = {
		image_id = 6410277917,
		rows = 1,
		columns = 0,
		fps = 30,
		frames = 5,
		full60fps = false,
	},
	['bf_menu_HEY!'] = {
		image_id = 6410277917,
		rows = 1,
		columns = 0,
		fps = 10,
		frames = 3,
		full60fps = false,
	},
	['template'] = {
		image_id = 1234567890,
		rows = 1,
		columns = 1,
		fps = 30,
		frames = 10,
		full60fps = false,
	},
}
 

local image = img
local currentFrame = 1
local currentRow,CurrentColumn = 0,0
local linear = false
local rows,columns = 0,0
local fps = 1
local frames = 0
local full60fps = true
local size = img.Size

function setup_gif(id)
	local gif = gifs[id]
	if gif then else return end
	rows = gif.rows
	columns = gif.columns
	currentRow,CurrentColumn,currentFrame = 1,1,1
	full60fps = gif.full60fps
	fps = gif.fps
	frames = gif.frames
	image.Image = 'rbxassetid://' .. gif.image_id
end

setup_gif('bf_menu_HEY!')

while true do
	if not full60fps then wait(1/fps) else game:GetService("RunService").Stepped:Wait() end
	if linear then
		print("linear animation")
	else
		CurrentColumn = CurrentColumn + 1
		if CurrentColumn > columns then
			CurrentColumn = 1
			currentRow = currentRow + 1
		end
		if currentFrame > frames then
			currentRow,CurrentColumn,currentFrame = 1,1,1
		end
		currentFrame = currentFrame+1
	end
end
1 Like

Oh wait, I get why It’s not working :sweat_smile: ImageLabels use ImageRectOffset and I just deleted the studspertile which I think is what makes it work. So I would have to change studspertile to ImageRectOffset

1 Like

But, I dont know how I would do that, since the image im using is at roblox’s max image size, and I dont know how to find the way to change the frame with imagerectoffset automatically.

I don’t either, I don’t know much about UI images. You should probably make a new post about it, or see if someone will answer here

1 Like

Sorry for the bump, but I have a good module that could help.