So when I equip my weapon, it works normally, and when I unequip it works normally as well, but if I do it again it breaks and gives me an error.
This the event which gets the error:
Event.OnServerEvent:Connect(function(player, state, item, animation)
local char = player.Character or player.CharacterAdded:Wait()
if state == "Equip" then
local Humanoid = player.Character:FindFirstChildOfClass("Humanoid")
local bp = player.Backpack[item.Name]:Clone()
--Humanoid:EquipTool(clone)
--item2.Parent = player.Backpack
char.Animate.toolnone:WaitForChild("ToolNoneAnim").AnimationId = "http://www.roblox.com/asset/?id="..animation
Update.UpdateWeapon(player, item.Stats.Serial.Value)
elseif state == "UnEquip" then
Update.UpdateWeapon(player, 0)
end
end
This is the script that fires it:
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Parent.Name == "Sword" then
local clone = script.Parent.Parent:Clone()
script.Parent.Parent:Destroy()
clone.Parent = player.PlayerGui.Inventory.Inventory.Inventory
EquipEvent:FireServer("UnEquip")
elseif script.Parent.Parent.Parent.Name == "Inventory" then
local frame = script.Parent.Parent
Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame)
end
end)
So I tried many different things, and is there any way to make a better system for Equipping/Unequipping tools.
Check.Checkit = function(player, open1, open2, frame, about)
if open1 == true and open2 == true then
if about == "Sword" then
for i, v in pairs(frame:WaitForChild("ItemView"):GetChildren()) do
EquipEvent:FireServer( "UnEquip", v, v.AttackScript.Animation.Id.Value)
end
elseif about == "Inv" then
if #player.PlayerGui.Inventory.Character.Sword:GetChildren() == 1 then
print("Something is currently equipped!")
else
frame.Parent = player.PlayerGui.Inventory.Character.Sword
frame.Size = UDim2.new(1,0,1,0)
frame.Position = UDim2.new(0.5,0,0.5,0)
for i, v in pairs(frame.ItemView:GetChildren()) do
EquipEvent:FireServer( "Equip", v, v.AttackScript.Animation.Id.Value)
end
end
end
end
end
Do the children of “ItemView” exist on the server? You can check that by clicking on play and clicking on “current client” to change studio to server mode.
Edit: Sorry, I just checked it doesn’t move from the inventory to the sword frame. It only stays in the inv. The children of the ItemView are still there.