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