I would like to achieve a script that can be parented by a model and drop the wood tools on the ground. I would like someone to help me with this script.
For some reason, it does not work. I would like it to be able to be parented by a model. Please help me with this.
It should go in the player’s inventory. I am checking if the Machete is activated when it touches the tree.
I would like all the parts to be affected at once. Please make it so I do not have to rename anything. It is in the model of the wood in the tree. It is not a union and I would not like to union about 5000 parts. I would like all the parts to be chopped at the same time. Do not edit the leaves
Here is a image and the script:
logs = script.Parent:GetChildren()
script.Parent.Touched:Connect(function(hit)
if hit.parent.name == "Machete" then
if hit.parent.Activated:Connect (TreeWood) then
end
function TreeWood()
if logs.Transparency == 0 then
logs.CanCollide = false
logs.Transparency = 0.5
local clone = game.ReplicatedStorage.ToolsDrops.Wood:Clone()
clone.Parent = game.Players.LocalPlayer.Backpack
wait(10)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
end
end
end
end)
Please give me some more details of what you are trying to do, when a Machete touches a tree, it should drop wood at the current postion of the torso of the player? But you are checking if Machete is touching it? Wouldn’t this script belong in the tree?
In order to get all the parts, you can use the :GetChildren() function and use a loop.
It would like something like:
local Tree = game.Workspace.Tree
for i, v in pairs(Tree.Stump:GetChildren()) do -- GetChildren() returns a table, and we can use a loop to iterate through it
if v:IsA("BasePart") then -- make sure it's a part and not the script
-- whatever you want to do with the part (v)
end
end
Do I do it like this?
``lua
logs = script.Parent:GetChildren()
local Tree = script.Parent.Parent
script.Parent.Touched:Connect(function(hit)
if hit.parent.name == “Machete” then
if hit.parent.Activated:Connect (TreeWood) then
end
function TreeWood()
if logs.Transparency == 0 then
for i, v in pairs(Tree.Stump:GetChildren()) do -- GetChildren() returns a table, and we can use a loop to iterate through it
if v:IsA("BasePart") then -- make sure it's a part and not the script
-- whatever you want to do with the part (v)
logs.CanCollide = false
logs.Transparency = 0.5
local clone = game.ReplicatedStorage.ToolsDrops.Wood:Clone()
clone.Parent = game.Players.LocalPlayer.Backpack
wait(10)
script.Parent.CanCollide = true
script.Parent.Transparency = 0
end
end
end
end
end
end)
local stump = script.Parent
local children = stump:GetChildren()
for i, v in pairs(children) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent.Name == "Machete" then
-- I don't know what you want to do to the logs so just put that here
end
end)
end
end