I've been having this issue in my tree-cutting game where I'm trying to give the player wood that he/she can carry around. (Don't worry, there's a lot more to the game than that) so, I tried many different techniques to do this. Unfortunately, like all of my scripts, they didn't work.
So what happens is: The player clicks on the tree and the tree disappears until it regnerates. I want to make it so that the player recieves a block of wood for every tree they cut down.
I also used Instance.new to model a tool handle because I figured it wouldn't be that difficult because it's literally just a block of wood.
Here's my code edit it all you want.
local pines = game.Workspace.Game.Forests.PinePoint --Pine Point is the name of the forest and Forests is the folder.
local pine = pines:FindFirstChild(pines.PineTree)
local tool = Instance.new("Tool")
tool.Name = "Pine"
local handle = Instance.new("Part")
handle.Parent = tool
handle.Material = Enum.Material.Wood
handle.BrickColor = BrickColor.new("Pine Cone")
pines.ChildRemoved:Connect(function()
local function giveTool(player, tool)
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
tool.Parent = backpack
end
end
end)
(go easy on me with the obvious answers)

1 comment
I don't understand why you'd be defining a function inside of an anonymous function, but it's your script.