Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Iterating through a spritesheet in order?

Asked by 4 years ago

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.

0
Could it be the image is pending review/is moderated/ wrong id? iOwn_You 543 — 4y
0
Oh, yes it was, thank you lol bpanasider 39 — 4y
0
Provide an answer and mark the question as solved if it's fixed User#834 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
Ad

Answer this question