I am working in one equip system for one simulator using StringValues and it works. The problem is you can keep equiping the same thing ( all 3 strings having the same value)
GIF:
The script is something like this:
Equip_Button.Button.MouseButton1Click:Connect(function()
for _, v in pairs(plr.Main_Values.PlrSettings:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == "" then
v.Value = SelectedPetValue.Value
break
elseif v.Value ~= SelectedPetValue.Value then
v.Value = SelectedPetValue.Value
break
end
end
end
end)
Note: SelectedPetValue.Value is one string when you click the pet gui you want this gui changes with the pet ID and if you click the Equip button the slot will have this String Value
Well you are looping through all of them so it changed all, if you want a certain one you could have either a table of those strings and just pass in a name or an number increasing and do :FindFirstChild(“blahblah”…n)
I am using break for change only 1 the problem is I dont know what I could use for see if the string alr got that value for not skip to others like if == something then (not skip to other string and try to find the string with that value) I cant use v.Value[SelectedPetValue.Value]
yes I just want to equip 1 time that value and if the player alr have that value equiped not change it if the player not have that value will skip into other StringValue.
Quick question though.
Let’s say the first value is “Pet1”, and now the player wants to equip “Pet2”. should it remove “Pet1”, or skip to the next empty value?
local function isEquippedAlready(SelectedPet)
for _, v in pairs(game.Players.LocalPlayer.Main_Values.PlrSettings:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == SelectedPet.Value then
return true
end
end
end
return false
end
script.Parent.MouseButton1Click:Connect(function()
if isEquippedAlready(SelectedPetValue) == false then
for _, v in pairs(game.Players.LocalPlayer.Main_Values.PlrSettings:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == "" then
v.Value = SelectedPetValue.Value
break
end
end
end
end
end)
Try this. I don’t know if this is what you meant, let me know if anything should be changed.
You don’t have a check to see if the string already existed or not.
Equip_Button.Button.MouseButton1Click:Connect(function()
local settings = plr.Main_Values.PlrSettings:GetChildren()
for _, v in pairs(settings) do
if v:IsA("StringValue") then
if v.Value == SelectedPetValue.Value then
return
end
end
end
for _, v in pairs(settings) do
if v:IsA("StringValue") then
if v.Value == "" then
v.Value = SelectedPetValue.Value
break
elseif v.Value ~= SelectedPetValue.Value then
v.Value = SelectedPetValue.Value
break
end
end
end
end)