How to have strings with different values?

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)
1 Like

I alr tried to see in devforum posts to find the issue. I cant make like one save for not use the same value?

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.

1 Like

but how I could do that in this script?

Like how I could use it to make one “check” in all strings.Value for see if is not == SelectedPetValue.Value??

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.

I am using local for test but I will use RemoteEvents for make it save.

How I can apply that in my script?? I dont see how I could use it.

Simply before equipping check if the pet is equipped using the function above

local petVal = SelectedPetValue.Value
if not isPetEquipped(petVal) then
  -- equip here
end
1 Like

sorry for the delay

Ok this is what I am doing.

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)

This is what happens.

ok wait nvm I forgort I could use tables to save past values… :man_facepalming: 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)