Equip_Button.Button.MouseButton1Click:Connect(function()
local settingsToChange
for _, v in pairs(plr.Main_Values.PlrSettings:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == SelectedPetValue.Value then
return
elseif not settingsToChange or settingsToChange.Value ~= "" then
if v.Value == "" then
settingsToChange = v
else
settingsToChange = v
end
end
end
end
settingsToChange = SelectedPetValue.Value
end)
I shortened the code but still couldn’t locate the problem.
I did one small change. But now I can add new values (sorry for the delay I was afk)
Equip_Button.Button.MouseButton1Click:Connect(function()
local settingsToChange
for _, v in pairs(plr.InventoryValues.AllPlrValues:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == SelectedPetValue.Value then
print("test")
return
elseif not settingsToChange or settingsToChange.Value ~= "" then
if v.Value == "" then
v.Value = SelectedPetValue.Value
break
else
v.Value = SelectedPetValue.Value
break
end
end
end
end
settingsToChange = SelectedPetValue.Value
end)
what you could do is use a for loop within a function and make it return true if there is one with the same string or by default return false if not
local function checkPet(slot, value)
for k,v in pairs(plr.Main_Values.PlrSettings:GetChildren()) do
if (v.Value == value and v ~= slot) then
return true
end
end
return false
end
--Then you can use an if statement like this
if (not checkPet(slot1, value)) then
end
If this helps/fixes youir problem please set as solution!
local folder = workspace.Folder --Folder of StringValue instances.
local function onStringChanged(stringValue, newString)
if newString ~= "" then
for _, otherString in ipairs(folder:GetChildren()) do
if otherString:IsA("StringValue") then
if otherString ~= stringValue then
if otherString.Value == newString then
stringValue.Value = ""
return
end
end
end
end
end
end
for _, stringValue in ipairs(folder:GetChildren()) do
if stringValue:IsA("StringValue") then
stringValue.Changed:Connect(function(newString)
onStringChanged(stringValue, newString)
end)
end
end
This will prevent a folder of StringValue instances from storing the same string (ignoring empty string values).
Nothing changed. I tried to take in @Imaginalities script and I changed a little bit and it works if I had only 1 string.
1 string Exemple:
If I had 3 values exemple:
Is like the script doesnt want to see all values inside the player and just stay with 1 string.
The script is something like this:
Equip_Button.Button.MouseButton1Click:Connect(function()
wait()
local settingsToChange
for _, v in pairs(plr.InventoryValues.AllPlrValues:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == SelectedPetValue.Value then
return
elseif not settingsToChange or settingsToChange.Value ~= "" then
if v.Value == "" then
v.Value = SelectedPetValue.Value
print(v.Value, SelectedPetValue.Value)
break
else
v.Value = SelectedPetValue.Value
print(v.Value, SelectedPetValue.Value)
break
end
end
end
end
settingsToChange = SelectedPetValue.Value
end)