Oh, it’s very intristing !
The equip and unequip work perfectly now.
But i’m facing a new problem.
When I click a tool, then press equip it works, then if I press unequip it works. But if i choose a new tool, it is stuck on the first tool.
Like if I equip tool 1 then unequip or re-equip it, it works and then if i equip tool2 it equips tool1
This is how my script works, get all plr’s tools, create a new template for each one, and if a template is clicked, make a gui appears, change all gui’s informations to tool info like name etc… and then if equipbutton is pressed:
equipButton.MouseButton1Click:Connect(function()
local equipped = tool:WaitForChild("Equipped").Value
if not equipped then
game.ReplicatedStorage.Remotes.EquipTool:FireServer(tool.Name)
equipButton.Text = "Unequip"
equipButton.BackgroundColor3 = Color3.fromRGB(165, 40, 9)
equipButton.BorderColor3 = Color3.fromRGB(126, 25, 0)
else
game.ReplicatedStorage.Remotes.UnequipTool:FireServer(tool.Name)
equipButton.Text = "Equip"
equipButton.BackgroundColor3 = Color3.fromRGB(0, 193, 0)
equipButton.BorderColor3 = Color3.fromRGB(0, 85, 0)
end
end)
this is the entire script without function wich sets the informations of the tool :
local Inventory = script.Parent
local frame = Inventory:WaitForChild("Frame")
local iFrame = Inventory:WaitForChild("IFrame")
local SFrame = frame:WaitForChild("ScrollingFrame")
local template = SFrame:WaitForChild("Template")
local desciption = iFrame:WaitForChild("Description")
local displayItem = iFrame:WaitForChild("DisplayItem")
local objectName = iFrame:WaitForChild("ObjectName")
local frameOpen = frame:WaitForChild("Open")
local iFrameOpen = iFrame:WaitForChild("Open")
local equipButton = iFrame:WaitForChild("EquipButton")
local ToolsOnglet = frame:WaitForChild("ToolsOnglet")
local BackpacksOnglet = frame:WaitForChild("BackpacksOnglet")
local PetsOnglet = frame:WaitForChild("PetsOnglet")
local module = require(Inventory:WaitForChild("GuiHolder"))
local function toolsDisplay()
for _, temp in pairs(SFrame:GetChildren()) do
if temp:IsA("TextButton") then
if temp.Name ~= "Template" then
temp:Destroy()
end
end
end
local plr = game.Players.LocalPlayer
for _, tool in pairs(plr.Inventory.Tools:GetChildren()) do
local newTemplate = template:Clone()
newTemplate.Name = tool.Name
newTemplate.ObjectName.Text = tool.Name
newTemplate.Visible = true
newTemplate.Parent = SFrame
local object = tool:Clone()
object.Parent = newTemplate.VPF
local cam = Instance.new("Camera")
cam.CFrame = CFrame.new(object.Handle.Position + (object.Handle.CFrame.lookVector*5),object.Handle.Position)
cam.Parent = newTemplate.VPF
newTemplate.VPF.CurrentCamera = cam
---- If player click an item (template) ----
newTemplate.MouseButton1Click:Connect(function()
local function SetupIFrame()
desciption.Text = tool:WaitForChild("Description").Value
objectName.Text = tool.Name
local rarity = tool:FindFirstChild("Rarity").Value
if rarity == "Common" then
objectName.TextColor3 = Color3.fromRGB(56, 56, 56)
elseif rarity == "Uncommon" then
objectName.TextColor3 = Color3.fromRGB(95, 180, 76)
elseif rarity == "Rare" then
objectName.TextColor3 = Color3.fromRGB(18, 59, 239)
elseif rarity == "Epic" then
objectName.TextColor3 = Color3.fromRGB(126, 0, 189)
elseif rarity == "Legendary" then
objectName.TextColor3 = Color3.fromRGB(225, 49, 25)
elseif rarity == "Secret" then
objectName.TextColor3 = Color3.fromRGB(22, 2, 83)
else
-- If any rarity is found then --
objectName.Text = "There was an error!"
end
for _, v in pairs(displayItem.VPF:GetChildren()) do
if v then
v:Destroy()
end
end
local object2 = tool:Clone()
object2.Parent = displayItem.VPF
local cam2 = Instance.new("Camera")
cam2.CFrame = CFrame.new(object2.Handle.Position + (object2.Handle.CFrame.lookVector*5), object2.Handle.Position)
cam2.Parent = displayItem.VPF
displayItem.VPF.CurrentCamera = cam2
local equipped = tool:WaitForChild("Equipped")
if tool.Unequipped then
equipButton.Text = "Equip"
equipButton.BackgroundColor3 = Color3.fromRGB(0, 193, 0)
equipButton.BorderColor3 = Color3.fromRGB(0, 85, 0)
else
equipButton.Text = "Unequip"
equipButton.BackgroundColor3 = Color3.fromRGB(165, 40, 9)
equipButton.BorderColor3 = Color3.fromRGB(126, 25, 0)
end
end -- End of the function --
if not iFrameOpen.Value then
SetupIFrame()
module.OpenIFrame()
iFrameOpen.Value = true
else
module.CloseIFrame()
wait(1.2)
SetupIFrame()
module.OpenIFrame()
end
equipButton.MouseButton1Click:Connect(function()
local equipped = tool:WaitForChild("Equipped").Value
if not equipped then
game.ReplicatedStorage.Remotes.EquipTool:FireServer(tool.Name)
equipButton.Text = "Unequip"
equipButton.BackgroundColor3 = Color3.fromRGB(165, 40, 9)
equipButton.BorderColor3 = Color3.fromRGB(126, 25, 0)
else
game.ReplicatedStorage.Remotes.UnequipTool:FireServer(tool.Name)
equipButton.Text = "Equip"
equipButton.BackgroundColor3 = Color3.fromRGB(0, 193, 0)
equipButton.BorderColor3 = Color3.fromRGB(0, 85, 0)
end
end)
end)
end
end
ToolsOnglet.ToolImage.MouseButton1Click:Connect(function()
toolsDisplay()
end)
Do you know why it is stuck?