Code not working as intended and stated

So, I started writing code for my UI since yesterday and I’ve been stuck with this one really annoying issue that I somehow cannot seem to locate myself ( Could be cause of my mental disabilities that make me unable to comprehend the issue, which is why I am asking for help with this. ).

The issue is rather simple, but I for the love of god cannot figure out what causes it,
long story short, I have a list of frames that upon clicking fire a remote to equip a pet, code:

for k, v in pairs(team.PetList:GetChildren()) do

	if v:IsA("Frame") then
		v.ImageButton.MouseButton1Click:Connect(function()

			if petSelected == '' then

				handlers.FunctionHandler:InvokeServer('EquipPet', v.petName.Value, 0, false)

			else

				handlers.FunctionHandler:InvokeServer('EquipPet', petSelected, v.Name, true)

			end

		end)
	end

end

and the function for the remote:

Bindables.EquipPet.Event:Connect(function(player, petName, spot, equip)
	
	local data = userDatas[player.userId].pets
	
	if equip then
		
		for _, v in pairs(data) do
			if v.equipped and v.slot == spot then
				v.slot = true
				v.equipped = false
			end
		end
		
		data[petName].equipped = true
		data[petName].slot = spot
		
	else
		
		data[petName].equipped = false
		data[petName].slot = false
		
	end
	
end)

The issue is, whenever I press one of the buttons inside the list, it equips ALL of the pets into the same slot no matter what I do, I tried to spam the buttons and after a while the code managed to work as intended (???) - I only managed to replicate the fix 3 times, it seems to be very random.

I made it print the variables and they seem fine, but for some odd reason the code just affects every single pet I have in the inventory instead of the specifically selected one despite specific statements in the code.

(Pets:171 - prints selectedPet and petSlot)
(DataHandler:227 - prints player, selectedPet, petSlot and equip)
(DataHandler:228 - prints pet data before edits)
(DataHandler:249 - prints pet data after edits)


I edited the rest of the code that’s in any sort of way connected to this one, and it isn’t what’s causing the issue which is why I specifically show only these scraps, I personally feel like it could be something with the EquipPet.

I’d appreciate any sort of help or navigation with what could possibly be the issue, so far I’ve only managed to narrow it to those two pieces of code, I don’t know what could be the issue with them though.

Small update on the issue:
I also tried firing the remote specifically from the console, it seems to be an issue with the remote rather than the ui buttons themselves

Quick question, when Invoking the server, is a argument missing in the server code?

client:

handlers.FunctionHandler:InvokeServer('EquipPet', v.petName.Value, 0, false)

server:

Bindables.EquipPet.Event:Connect(function(player, petName, spot, equip)

Yeah, I use a handler that then uses a module named the same as the command (first argument)

local functions = (function() 
	local list = {}
	
	local function scan(part)
		for k, v in pairs(part:GetChildren()) do
			if v:IsA("ModuleScript") then
				list[v.Name:lower()] = require(v)
				list[v.Name] = require(v)
			end
			
			scan(v)
		end
	end
	
	scan(script)
	
	return list	
end)()

game.ReplicatedStorage.Handlers.EventHandler.OnServerEvent:Connect(function(plr, command, ...)
	local args = { ... }
	
	if functions[command:lower()] then
		functions[command:lower()]( 'event', plr, args )
	else error( ("Couldn't find command %s"):format( command ) )
	end
end)

game.ReplicatedStorage.Handlers.FunctionHandler.OnServerInvoke = function(plr, command, ...) 
	local args = { ... }
	
	if functions[command:lower()] then 
		return functions[command:lower()]( 'function', plr, args )
	else error( ("Couldn't find command %s"):format( command ) )
	end
end

and then i just got

local localLibraries = game.ReplicatedStorage.Libraries
local serverLibraries = game.ServerScriptService.Libraries

local bindables = game.ServerScriptService.Bindables

local delays = {}

return function(cmdType, plr, args)
	bindables.EquipPet:Fire(plr, args[1], args[2], args[3])
end

inside EquipPet module

Basically just:
image

But to clarify as I just checked,
the handler itself isn’t the issue either, since if i fire the main bindable from server same issue occurs:
image

Yes! I fixed it now, thanks for anyone who tried to help me in private messages.

For some reason, re-publishing the place to another one and screwing with place settings fixed it?..
It’s rather odd to say the least, but it works now!

image

1 Like