#How to make replacing instances with different names?

1 messages · Page 1 of 1 (latest)

fluid warren
#

I have a couple folders, and only one can be part of the player at a time. I have a function for this in leaderstats, and I can give them the new file, but I can't figure out how to get rid of the old one. Can someone help?

round gorge
#

your specChange function is destroying everything inside the player including some that are probably irrelevant (like backpack)

#

you are checking if the value's name isn't named Spec

#

i think you meant to do == rather than ~= ?

#

@fluid warren

fluid warren
fluid warren
#

that's the main problem I'm getting, I need to be able to find the old file who's name matches what the string value used to be before it changed

#

just changed it

#

hold up I was searching in the player instead of the character i'm so dumb

#

thanks for the help man

round gorge
#

oh

#

good to know you got around your issue

fluid warren
#

thanks i have problems like this all the time

round gorge
#

i came here becuase i had a problem and im just helping random people now lol

fluid warren
#

lmao

#

wait actually new problem

#

I set oldSpec outside of the function so it only sets once, if I change it again it'll only search for the original definition

round gorge
#

wait what are you exactly trying to achieve

#

i dont really understand

fluid warren
#

ok so I want to make a kinda replacement system, a player can only have one "spec" at a time, and if they get a new one, it replaces whatever spec they had before

round gorge
#

is that "spec" a tool inside the character?

fluid warren
#

nah its a file

round gorge
#

hmm okay

fluid warren
#

I need to define the spec they had beforehand and destroy it, but idk how to define it and replace the definition if it's already set

round gorge
#

is there anything in common that all these specs have

fluid warren
#

closest thing I can think of is that they all have a script with the same name in them

round gorge
#

okay, that works

fluid warren
#

lemme try that rq

#

ok weird problem, it searches everything but stops when something doesnt meet the definition

round gorge
#

hold on you gotta find the folder with that script inside it and destroy that folder then put the new folder

round gorge
fluid warren
round gorge
#

hold on

#

what is that script named?

#

that all specs have

fluid warren
#

InputScript

round gorge
#

hmm i think you could use a findfirstchild that would check if any of the character's children have a script called InputScript, but i forgot what it was called

#

:FindFirstAncestor() i think

#

try Char:FindFirstAncestor("InputScript")

fluid warren
#

oh smart actually

#

saves me a nest?

round gorge
#

i mean i dont know the behind of that method

#

so it could be doing the same thing lol

fluid warren
#

something like this?

round gorge
#

oh no i think ancestor is something else

fluid warren
#

it can't index the input script

round gorge
#

hold on ill research

fluid warren
#

oh descendent

round gorge
#

ancestor is a diffrent thing yeah

#

it starts from the script and goes up

fluid warren
#

i have to enable it??

#

this is weird

round gorge
#

i mixed it up wait

fluid warren
#

yeah we confused descendant with ancestor i think

round gorge
#

yeah

fluid warren
#

it says i have to enable the function though

round gorge
#

would it cause any issue if you were to rename the folder to "Spec"

#

all spec folders

fluid warren
#

yeah there's some things ServerSide I want to only work with that specific folder

round gorge
#

or make it have its last 4 letters be Spec

#

could that work?

fluid warren
#

ig that would work yeah

round gorge
#

okay one second

#
local function getSpecFolder(character)
    for _, child in character:GetChildren() do
        if child:IsA("Folder") and string.sub(child.Name, -4) == "Spec" then
            return child
        end
    end
    return nil -- if no spec folder
end
#

then you can do
local SpecFolder = getSpecFolder()
if SpecFolder then SpecFolder:Destroy() end

#

@fluid warren

fluid warren
#

ok hold up so it searches the character for a folder and then checks if it ends in "Spec", if it finds it, it returns the function

round gorge
#

yes

fluid warren
#

wow nice

round gorge
#

it returns the child

fluid warren
#

that seems a lot safer than what i came up with actually

round gorge
#

just make sure there is nothing else that ends with spec

#

Spec, first letter is capitilized

fluid warren
#

alr lemme try that

#

okay that just triggered some horrible butterfly effect

round gorge
#

what happened?

fluid warren
#

it deleted everything in my player's other folders

#

which is weird because it's only effecting the character

round gorge
#

huh

fluid warren
#

idk man i undid all of it too and it's still doing it

#

ok mb I forgot to redefine some variables

knotty cedarBOT
#

studio** You are now Level 10! **studio

fluid warren
#

it works fine now, thanks man 💯