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
7 years ago
Edited 7 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.

01local function functioner()
02    canFunction = false
03    local ToolType = Tool.ToolType
04    local ToolTypeNeeded = hit.Parent.ResourceManagement:FindFirstChild("ToolTypeNeeded")
05    if ToolTypeNeeded.Value == ToolType.Value then
06        local resourceHealth = hit.Parent.ResourceManagement:FindFirstChild("ResourceHealth")
07        if resourceHealth.Value >= 1 then
08            resourceHealth.Value = resourceHealth.Value - damage
09            Tool.Handle.Sounds.Hit:Play()
10            local function dropResources()
11                if resourceHealth.Value <= 0 then
12                    local resourceType = hit.Parent.ResourceManagement.ResourceType.Value
13                    local resourceModule = require(game.ServerScriptService.Modules.ResourceModules.ResourceDropModule)
14                    resourceModule[resourceType]()
15                    local main = hit.Parent.Main
View all 24 lines...

And here is the module script that I currently have.

01local drops = {}
02 
03function drops.SmallTree()
04    local wood = game.ServerStorage.ResourceDrops.Wood
05    local sapling1 = game.ServerStorage.ResourceDrops.Sapling1
06 
07    local TreeDrops = {wood, sapling1}
08 
09    for i = 1, 2 do
10 
11        local ItemDrop = math.random(1, # TreeDrops)
12 
13        local Item = TreeDrops[ItemDrop]
14 
15        local dropped = Item:Clone()
View all 24 lines...

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

Answer this question