I am making one Pet equip system with Strings the problem is I only can manage 1 string I cant manage other strings
Exemple if you try to equip the same pet
Now if you select other
What I am trying to do: I am trying to make one equip system but I dont want the player be able to equip the same value 3 times
Exemple: FirstString will be “A”, SecoundString will be “B” and the other will be “C” BUT we dont want the player be able to equip “A” for +1 time (We dont want FirstString and SecoundString to have the same value)
Here the script:
Equip_Button.Button.MouseButton1Click:Connect(function()
wait()
for _, v in pairs(plr.InventoryValues.AllPlrValues:GetChildren()) do
if v:IsA("StringValue") then
if v.Value == "" and v.Used.Value == "" then
v.Value = SelectedPetValue.Value
v.Used.Value = "On"
print("Test1")
break
end
end
end
end)
You can make a check to see if that value[pet] has been equipped already , and if so, return ‘Equipped already!’ or something with your functions and stuff.
You can make a simple function that checks if given pet is already being used in other slot.
local function isPetEquipped(petId)
for _, v in next, plr.InventoryValues.AllPlrValues:GetChildren() do
if (v:IsA('StringValue') and v.Value == petId) then
return true
end
end
return false
end
It also seems like you’re handling the pets locally. This is not how you do it - after the player attempts to equip a pet, you should send a remote function/event to the server.
Then the server should be responsible for setting the values which can be read later on by the local scripts.
local function isPetEquipped(petId)
for _, v in next, plr.InventoryValues.AllPlrValues:GetChildren() do
if (v:IsA("StringValue") and v.Value == petId and v.Used.Value == "") then
return true
end
end
return false
end
Equip_Button.Button.MouseButton1Click:Connect(function()
local petVal = SelectedPetValue.Value
if not isPetEquipped(petVal) then
for _, v in pairs(plr.InventoryValues.AllPlrValues:GetChildren()) do
if v:IsA("StringValue") then
v.Value = SelectedPetValue.Value
v.Used.Value = "On"
break
end
end
end
end)
ok wait nvm I forgort I could use tables to save past values… sorry…
the script is something like this:
local Testing_Value = {}
Equip_Button.Button.MouseButton1Click:Connect(function()
wait()
for _, v in pairs(plr.InventoryValues.AllPlrValues:GetChildren()) do
if v:IsA("StringValue") then
if v.Used.Value == "" and Testing_Value ~= nil then
if Testing_Value[1] ~= SelectedPetValue.Value and Testing_Value[2] ~= SelectedPetValue.Value and Testing_Value[3] ~= SelectedPetValue.Value then
v.Value = SelectedPetValue.Value
table.insert(Testing_Value, SelectedPetValue.Value)
print(Testing_Value)
break
end
end
end
end
end)