Hi, what i’m trying to do is detect if there are any duplicate stringvalues that have the same name. What would I do scripting wise to achieve this?
Why are you trying to do this? What is your ultimate goal? There may be a better way to achieve what you want.
This is just to see if a player has a the same character in their inventory.
I don’t know why you need to do something like that when you can check if a stringvalue
exists before creating a new one in the first place but in order to detect duplicate stringvalue
s for your case, you need to do something like this:
local Childs = script:GetChildren() --You can edit this for whatever fits for you.
local StringValueNames = {} --A table just to put the original string value names in.
for i,v in ipairs(Childs) do
if v:IsA("StringValue") then
if table.find(StringValueNames,v.Name,1) == nil then
table.insert(StringValueNames,#StringValueNames+1,v.Name) --Inserts a new stringvalue name because there wasn't one in the table.
else
v:Destroy() --Destroys the string value because another stringvalue with the same name exist.
end
end
end
you can use string.match() or string.find()
Its simple enough and the wiki can explain everything well enough.
Source:
If your doing this you could just test in studio and open the explorer and then type in the name of the duplicate value which might be faster than trying to make a script for it.
What does that mean? How does a player have a character in their inventory?
It’s the string value of the character’s name. Not the actual object of the character.