Ipairs on client side?

Hey everyone, I couldn’t find any other forum topics relating to this so here we go.
I wish to have multiple lights change at once with a client sided script using ipairs, (the Script in question is not a LocalScript, it is a regular Script with the RunContext on Client). However, I can’t seem to get ipairs to work on the Client, only the Server.

Here is the code, my friend had tried to teach me how to use ipairs himself and I kinda get it.
Screenshot 2024-08-01 174305

1 Like

Why are you using task.defer here? There’s no real benefit or performance increase because of how quickly that code will execute. Try printing each v value every iteration, could be that the parts didn’t load before the script run (that happens with LocalScripts, not sure with Scripts with RunContext set to Client because they are a child to the instance).

The issue is not to do with your use of ipairs. All ipairs does is return an iterator and the table.

1 Like

is lights a folder?, explain please.

No, the lights are a model, I could try to put them in a folder.

My friend had said I should use task.defer, I’m not sure, never used it before…
I’ll give it a shot though.

I would try to do it in a local script and put it in starter character scripts, or just do it on the server and keep the run context on server

This seems to have worked. I disabled the script and put a delay that would enable the script after 5 seconds, (when everything should be properly loaded in). All the lights did indeed change how I wished them to.

Glad I could help. Try replacing the 5 second wait with a statement at the top of your client script:

repeat task.wait() until game:IsLoaded()

It might work better.

1 Like

Oh well that is really handy, thanks!

EDIT: Tried it and for some reason its back to not doing anything.

don’t use it, I had a feeling it might not work in this context but if it did it would be better. Just use the other wait statement.

Alrighty, thanks though, I’ll use it in the future if i have to.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.