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

How can I make items appear at a tool's hit.Parent's location?

Asked by
Duksten 20
6 years ago
Edited 6 years ago

So I'm having a bit of trouble finding out how to get items to appear to a tool's hit.Parent's location. I have a script that deals with the tool's handle interacting with a resource that it detects its hit.

Plus I also have a module script that is responsible for selecting a random number or type of item that will be dropped, and that module script is then requested in the tool's script when it's needed.

The problem is I'm having trouble with making sure that the items appear at the tool's hit.Parent's position.

Here is the function from the tool's script.

    local function functioner()
        canFunction = false
        local ToolType = Tool.ToolType
        local ToolTypeNeeded = hit.Parent.ResourceManagement:FindFirstChild("ToolTypeNeeded")
        if ToolTypeNeeded.Value == ToolType.Value then
            local resourceHealth = hit.Parent.ResourceManagement:FindFirstChild("ResourceHealth")
            if resourceHealth.Value >= 1 then
                resourceHealth.Value = resourceHealth.Value - damage
                Tool.Handle.Sounds.Hit:Play()
                local function dropResources()
                    if resourceHealth.Value <= 0 then
                        local resourceType = hit.Parent.ResourceManagement.ResourceType.Value
                        local resourceModule = require(game.ServerScriptService.Modules.ResourceModules.ResourceDropModule)
                        resourceModule[resourceType]()
                        local main = hit.Parent.Main

                    end
                end
                dropResources()
            end
        end
        wait(damageCoolDown)
        canFunction = true
    end

And here is the module script that I currently have.

local drops = {}

function drops.SmallTree()
    local wood = game.ServerStorage.ResourceDrops.Wood
    local sapling1 = game.ServerStorage.ResourceDrops.Sapling1

    local TreeDrops = {wood, sapling1}

    for i = 1, 2 do

        local ItemDrop = math.random(1, # TreeDrops) 

        local Item = TreeDrops[ItemDrop]

        local dropped = Item:Clone()

        dropped.Parent = game.Workspace


    end
end


return drops

In the case of the tree, it should appear at hit.Parent.Main's position.

Answer this question