Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Iterating through a spritesheet in order?

I'm making a gun spritesheet that changes the image based on the ammo.

I have 30 images in a table.

local circular = {"rbxassetid://123123123","rbxassetid://123123124"} --etc etc

I tried this

userInput.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		ammo = ammo - 1
		
		image.Image = circular[ammo]
		
	end
end)

Then I get this error; 13:25:10.171 - Image "https://assetdelivery.roblox.com/v1/asset?id=73737627" failed to load in "Players.bPanasider.PlayerGui.ScreenGui.ImageLabel.Image": Request failed

I read up on people using RectOffset and stuff but I don't know why I need that stuff, I'm using one imagelabel with a bunch of images that are the exact same dimensions, I just want to get a new one whenever the ammo goes down, eg: there is 30 ammo so it grabs the 30th one from the table, when ammo goes down I'll update the ui and grab the next one which would be 29.

3 comments

0

Could it be the image is pending review/is moderated/ wrong id?

0

Oh, yes it was, thank you lol

0

Provide an answer and mark the question as solved if it's fixed

1 answer

To loop through items in an array (if thats how you're storing the sprite sheet) in order use ipairs()

for i,v in ipairs() do
--whatever
end

This discussion is preserved as it was. New answers, comments, and votes are closed.