Selecting same name item does not go to the one i clicked?

what would i need to solve this issue?


local plr  = game.Players.LocalPlayer
local Module = require(script.Parent)




plr:WaitForChild("KatanaInventory").ChildAdded:Connect(function(v)
	local newtemp = Module.CreateTemplates(v)
	
	newtemp.MouseButton1Down:Connect(function()

			Module:Equip(v)
		
	end)
	
end)

for i,v in pairs(plr:WaitForChild("KatanaInventory"):GetChildren()) do
	local newtemp = Module.CreateTemplates(v)	
	
	newtemp.MouseButton1Down:Connect(function()
		Module:Equip(v)
	end)
	
end

game.ReplicatedStorage.Events.MobKillMessage.OnClientEvent:Connect(function(chosenKatana)
	
	local otherClonedKatanFX = chosenKatana:Clone()
	
	
	local clonedTemp = game.ReplicatedStorage.Events.SwordShow:Clone()
	clonedTemp.Parent = script.Parent.Parent.Parent.Details
	otherClonedKatanFX.Parent = clonedTemp.KatanaHolderShow
	game.ReplicatedStorage.Events.RegisterSword:FireServer(chosenKatana)
	local newcam = Instance.new("Camera", clonedTemp.KatanaHolderShow)
	clonedTemp.KatanaHolderShow.CurrentCamera = newcam
	newcam.CFrame = CFrame.new(otherClonedKatanFX.Handle.Position + Vector3.new(0,0,4)) 
	clonedTemp.katanaName.Text = chosenKatana.Name.." %"..chosenKatana.Chance.Value
	
	task.wait(1)
	
	clonedTemp:Destroy()
	
	
end)

the code above is my handling script where it loops through the inventory to create the templates.


local plr = game.Players.LocalPlayer


local selectedtemp = nil

local Inventory_Indexer = {}
Inventory_Indexer.__index = Inventory_Indexer



function Inventory_Indexer:Equip(k)
	local char = workspace:FindFirstChild(plr.Name)
	local v = script.Parent.Parent.Inventory.bg.ButtonHolder:FindFirstChild(k.Name)
	
	selectedtemp = v.Name
	
	
	
	if v.Equipped.Value == false and plr.KatanaEquippedAmount.Value == 0 then
		local result =  game.ReplicatedStorage.Events.EquipKatana:InvokeServer(v.Name)
		if result == true then
			for i,t in pairs(script.Parent.Parent.Inventory.bg.ButtonHolder:GetChildren()) do
				if t:IsA("ImageButton") then
					t.TickIcon.Visible = false
				end
				
			end
			task.wait(0.5)
			v.Equipped.Value = true
			print(selectedtemp)
		v.TickIcon.Visible = true
		end
		
		script["RBLX UI Camera (SFX)"]:Play()
	elseif v.Equipped.Value == true and plr.KatanaEquippedAmount.Value == 1 then
		local resultUn = 	game.ReplicatedStorage.Events.UnequipKatana:InvokeServer(v.Name)
		if resultUn == true then
			for i,t in pairs(script.Parent.Parent.Inventory.bg.ButtonHolder:GetChildren()) do
				if t:IsA("ImageButton") then
					t.TickIcon.Visible = false
				end

			end
			print(selectedtemp)
			v.Equipped.Value = false
		script["RBLX UI Camera (SFX)"]:Play()
		v.TickIcon.Visible = false
		end
		
	end
	
end


function Inventory_Indexer.CreateTemplates(v)
	
	local ClonedTemplate = script.Template:Clone()
	
	ClonedTemplate.Parent = script.Parent.Parent:WaitForChild("Inventory").bg.ButtonHolder
	ClonedTemplate.Name = v.Name
	
	
	local ClonedObj = game.ReplicatedStorage.KatanasFolder:FindFirstChild(v.Name):Clone()
	ClonedObj.Parent = ClonedTemplate.KatanaHolder
	
	local NewCam = Instance.new("Camera", ClonedTemplate.KatanaHolder)
	

	
	ClonedTemplate.KatanaHolder.CurrentCamera = NewCam

	NewCam.CFrame = CFrame.new(ClonedObj.Handle.Position + Vector3.new(0,0,4))
	
	return ClonedTemplate
end

return Inventory_Indexer

the code above is the one which handles the inventory like creating templates etc

It has to do with the script, you didn’t send your script but I assume that you are selecting the item based on name and not the one you actually click? If that’s the case then you need to make a way to identify which item is being clicked even though they have the same name. If that’s not the case then you’d have to send your script involving the issue for anyone to figure it out.

We’re going to need to see the script if you want us to debug this any further.

i just updated the post you can see the code now

i just updated the post you can see the code now

To select the correct sword, you could assign a certain number to it, and search for it using the number. Or you could search for it using the Position on the screen, use a ipairs loop to find the one with the provided position.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.