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

My custom equip script is not working and getting a code error?

Asked by
Galicate 106
6 years ago

I have disabled the backpack core gui so i could have a custom inventory system, and I made a script that when pressing 1 it equips the "Primary tool" and pressing 2 equips the "Secondary tool". I get the error: 16:22:18.964 - Unable to cast value to Object

local Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
local equipped = false
local primary = Player.PlayerData.Inventory.PrimaryTool.Value
local secondary = Player.PlayerData.Inventory.SecondaryTool.Value
print(primary.." "..secondary)

Mouse.KeyDown:connect(function(Key)
    if(Key:lower() == "1") then
        if equipped == false then
        Player.Character.Humanoid:EquipTool(primary)
        equipped = true
        print("equipped primary")
        elseif equipped == true then
        Player.Character.Humanoid:UnequipTools()
        equipped = false
        print("unequipped primary")
        end
        end
    if(Key:lower() == "2") then
        if equipped == false then
        Player.Character.Humanoid:EquipTool(secondary)
        equipped = true
        print("equipped secondary")
        elseif equipped == true then
        Player.Character.Humanoid:UnequipTools()
        equipped = false
        print("unequipped secondary")
        end
        end
end)
0
What line was the error on? Professor_Boxtrot 136 — 6y
0
Thanks. Galicate 106 — 6y
0
The error is occuring on lines 11 & 22 Galicate 106 — 6y

Answer this question