How can I make items appear at a tool's hit.Parent's location?
Asked by
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.
01 | local function functioner() |
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 |
And here is the module script that I currently have.
03 | function drops.SmallTree() |
04 | local wood = game.ServerStorage.ResourceDrops.Wood |
05 | local sapling 1 = game.ServerStorage.ResourceDrops.Sapling 1 |
07 | local TreeDrops = { wood, sapling 1 } |
11 | local ItemDrop = math.random( 1 , # TreeDrops) |
13 | local Item = TreeDrops [ ItemDrop ] |
15 | local dropped = Item:Clone() |
17 | dropped.Parent = game.Workspace |
In the case of the tree, it should appear at hit.Parent.Main's position.