I'm trying to make the player, whenever he/she clicks a gui button, equip a tool from the player's backpack. It says it keeps failing at line 15. The error is listed below. Can someone explain to me why it is giving me an error? (Yes, it is in a LocalScript.)
Error: Players.Player1.PlayerGui.Backpack.ScrollingFrame.AutoEquip:15: attempt to index global 'findval' (a nil value)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local player = game.Players.LocalPlayer
local character = player.Character
local tool = player.Backpack:GetChildren()
val = script.Parent.EquipedItem.Value
findval = player.Backpack:FindFirstChild(val)
function equip(tool)
findval:Clone().Parent = character
end
function unequip(tool)
findval:Destroy()
end
while wait() do
if val == "" then
unequip()
elseif val == "Sword" then
equip()
end
end
