How could i improve on this and make it more easy to read?

So i have a shop that players can buy from, Like emotes, cosmetics, you know, basic stuff like that.

Anyways, It works good, But the code is hard to read, and the whole thing is very unorganized, But im not sure how to fix it.

Some emotes are unobtainable, So they are either Admin-only, Or a secret.
What i did to make these not show up in the shop is by adding a boolvalue called “SecretEmote”, But this isnt very organized so i basically had to either guess, or open the emote to see if its secreted.

So then i thought, Hey, Maybe i could just make a seperate folder:
image
Cool, Its more organized, But now theres an issue with the code, I dont think its bad, but i think there could be a better way instead of having to check if its in either folder (i have to do this every time i want to check an emote in the code)

if emotes:FindFirstChild(emotename) or unobtainableEmotes:FindFirstChild(emotename) then
	--code
end

Or i have to do this:

local emoteinstance = emotes:FindFirstChild(emotename) or unobtainableEmotes:FindFirstChild(emotename)
if emoteinstance ~= nil and rewardinstance.Parent == emotes or emoteinstance.Parent == unobtainableEmotes then
	--give emote
end

And i have multiple items to buy, so i have to use a loop through the player’s owned stuff, and see if its in the unobtainable folder or not.
What i could do is using something like GetDescendants(), But theres alot of emotes, and there isnt only emotes and unobtainable emotes, theres remote events, and other folders there too, So it’d loop through those.
this is pretty frustrating, I just want to organize my code to make it nicer.

Any help is appreciated, And sorry if i got something wrong.

i’m assuming you’re talking about doing :GetDescendants() on the Instance that’s holding Emotes and Unobtainable

if that’s true then the problem is your emotes aren’t even organized properly
you could give the Obtainable emotes their own folder aswell

image

local Emotes = workspace:WaitForChild("Emotes") -- Set a path to emotes folder (my example was in workspace)

if Emotes:FindFirstChild("Dance1", true) then -- Recursive search through emotes folder
  -- The target emote could possibly be obtainable
end
1 Like

I have used the recursive search (for a different thing), Is it fine for performance? because theres gonna be a lot emotes

The main thing im worried about is performance.

i did a test with a thousand parts
image
even you had 10 thousand emotes, you still probably wouldn’t notice a significant difference

dang, didnt know that

after testing with it. yea it works great man thanks

1 Like

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