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

My tooldrop doesnt drop the tools at the NPC how to fix?

Asked by 2 years ago

So my script works but the tool gets dropped where the tool is placed anyone who knows how to fix?

local hum = script.Parent -- humanoid
local tfolder = game:GetService("ReplicatedStorage"):FindFirstChild("Items") -- finds the folder
local folderc = tfolder:GetChildren() -- gets the items on the folder

local IsModel = false -- check for model if its not a model leave it to false else set it to true
local IsRandom = true -- if set to false add a tool name to get the specific iten you want
local IsTool = false -- checks if its a tool or not IF IT IS A TOOL set it to true if not then flase
local ItemName = "" -- if israndom is set to true leave it blank

-- script part
hum.Died:Connect(function() -- function
    if IsRandom == true then
        if IsTool == false then
            local random = math.random(1, #folderc) -- randomizes
            local index = folderc[random] -- index the tool

            local item = index:Clone() -- clone the randomized tool
            item.Parent = game:GetService("Workspace") -- parent of the tool

            if IsModel == true then -- if it is a model or not dont change, only change the one on the variables
                item:MoveTo(hum.Parent.Head.Position) -- how we can move it because its a model
            else
                item.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the tool)
            end

            print("Random Item Dropped: "..index.Name) -- notify
        else
            local random = math.random(1, #folderc) -- randomizes
            local index = folderc[random] -- index the item

            local tool = index:Clone() -- clone the randomized item
            tool.Parent = game:GetService("Workspace") -- parent of the item
            tool.Handle.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the item)

            print("Random Tool Dropped: "..index.Name) -- notify
        end
    else -- if random is not in true
        if IsTool == false then
            local item = tfolder:FindFirstChild(ItemName):Clone() -- gets the tool ( finds the tool inside the folder
            item.Parent = game:GetService("Workspace") -- parent of the tool

            if IsModel == true then -- if it is a model or not dont change, only change the one on the variables
                item:MoveTo(hum.Parent.Head.Position) -- how we can move it because its a model
            else
                item.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the tool)
            end

            print("Item Dropped: "..ItemName) -- notify
        else
            local tool = tfolder:FindFirstChild(ItemName):Clone() -- gets the tool ( finds the tool inside the folder
            tool.Parent = game:GetService("Workspace") -- parent of the tool
            tool.Handle.CFrame = hum.Parent.Head.CFrame -- cframe ( position of the tool)

            print("Tool Dropped: "..ItemName) -- notify
        end
    end
end) -- end of function

Answer this question