#for [key] doesn't work

1 messages · Page 1 of 1 (latest)

ocean ingot
#

So this is a part of my function but for some reason script.Parent[key].Image = "rbxassetid://131999468534304" doesn't work even though the right key is getting printed with print(key) everything is how its suppose to be but it just doesn't work @-@
-# Attached an image of how my files are ordered

Not working code in Module HotbarScript

for key, value in pairs(SlotContent) do
        if value == "FlashLight" then
    print(key)    
    script.Parent[key].Image = "rbxassetid://131999468534304"

    end```
#

btw this is what the SlotContent table looks like if that is needed

local SlotContent = {
    slot1 = "Empty",
    slot2 = "Empty",
    slot3 = "Empty",
    slot4 = "Empty",
    slot5 = "Empty"
}```
gusty cargo
#

its becuse the the id is to long

#

it needs to be maximum 10 numbers

#

so, like if you used moon animator

ocean ingot
#

So what do I do!?

gusty cargo
#

did you used it?

#

moon animator?

ocean ingot
#

no..

gusty cargo
#

the normal roblox animation system?

ocean ingot
#

waaaa that is not even an animation the id is a picture that im trying to apply to an Image Lable

gusty cargo
#

ohhh

#

let me see

#

example: rbxassetid://112902314

surreal geyserBOT
#

studio** You are now Level 1! **studio

gusty cargo
#

it needs to be 10 numbers

#

try to look for another image

#

even if its an animation or an image, it needs to be max 10 numbers

ocean ingot
#

How do I know which image has a smaller number

#

This image I'm trying to apply is literally 32x32 pixels waaaa

gusty cargo
#

wait a second

ocean ingot
#

oh my god

#

wait I think I got it...

#

I just noticed there is two times rbxassetid://

#

wait..

#

the thing I sent there isnt 2 times rbxassetid:// thonk

#

okay now im just confused, give me a sec

#

Yeah okay it still doesnt work T.T

surreal geyserBOT
#

studio** You are now Level 2! **studio

ocean ingot
#

so what is the way to make the number smaller

gusty cargo
#

well, just try and add an decal to the part that you want to and paste this: rbxassetid://131999468534304

#

maybe it will work

#

i tried and it does

#

look

#

\

ocean ingot
#

hm

gusty cargo
#

i doesnt let me paste the image

#

but it works

ocean ingot
#

uhhh

#

nope ;-;
But I noticed that if I put it outside of the function and do something like script.Parent.slot1.Image = "rbxassetid://131999468534304" it will work

#

but I need it in the function waaaa

gusty cargo
#

oh

#

oh man

#

igtg

ocean ingot
#

Maybe someone else know

#

bye ;-;

gusty cargo
#

yeah

#

they are better than me

thin sand
#

And if you change it later down the runtime. Then you will have to rerun the code. Which is quite inefficient

#

It’s far better to just only change the slot that is affected by the change

#

This can all be easily managed by a FSM (google it, finite state machine). Just have equipping/using items change the hotbar images (and some back end data handling of course)

ocean ingot
#

I'm not sure, I think it does get run ;-;

ocean ingot
thin sand
#

How about we then start off by being clearer than “it doesn’t work”

#

As most folks just then assume it’s not printing (as that tends to be debug step 1)

ocean ingot
#

script.Parent[key].Image = "rbxassetid://131999468534304" should be changing the empty slot texture to a slot with a flash light picture but it doesn't. the slot just stays with the empty texture

thin sand
#

And manually inserting that id does cause it to correctly load the image, right?

ocean ingot
#

yes, but only if I put it outside the whole function

#

if I manually put it in while still being where it is it wont work ;-;

#

I feel like this is a type of mistake where I forgot to put a symbol somewhere or something like that

thin sand
#

Or just issues like having multiple UIs over each other, or something similar

ocean ingot
#

I will just look over everything one more time ;-;

thin sand
#

Would be better off by just debugging it with some better prints. E.g. starting off by looking at what roblox thinks the asset id is after you set it in the for loop

ocean ingot
#

I will just consider giving up for now and returning to it later

#

Maybe its a bug or something

ocean ingot
#

Update: okay so apperantly server scripts cant change UI's shrug_idk so when I setup the function a local script it started working now I just dont know how to call a local script function from a server script T.T