Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm trying to auto-equip a tool but it gives me "Unable to cast value to Object", why?

Asked by 3 years ago
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")

if not player.Character:FindFirstChildOfClass("Tool") then 
    player.Character.Humanoid:EquipTool("MK18") end

for index, tool in pairs (player.Backpack:GetChildren()) do
    if tool:IsA("Tool") and tool.Name == "MK18" then
        tool.Unequipped:Connect(function()
            tool.Parent = player.Character
        end)
    end
end

This code doesn't auto-equip my tool, Its in StarterPlayerCharacter and it gives me an error that says "Unable to cast value to Object"

0
you are trying to equip string "MK18" jerryisgod29 176 — 3y

Answer this question