So I am making a working ax and I am trying to loop through all of the trees so that you can cut them down. I got the ax itself working, I am just trying to make it so that you can chop down multiple trees. I have a function that loops through the trees, but when I call it, you can only chop down 1 tree, even if you chop down that 1 tree, and try to chop down another one. There is a lot of code here, so I didn't include it all, but for some reason, it doesn't work.

Here is my code:

view source

function getAllTrees()
	for _, tree in pairs(workspace.Trees:GetChildren())  do
		if tree:IsA("Model") then
			local owner = Instance.new("ObjectValue",tree)
			owner.Name = "Owner"
			owner.Value = player
			if owner.Value == player then
				return owner
			end
		end
	end
end

local owner = getAllTrees()

--there is code here, but I won't show it because it is so long LOL (in total, this script is  152 lines)

--there is code here, but I won't show it because it is so long LOL (in total, this script is 152 lines) Do I have to call it again in the activated event or what? Any help?

1 comment

0

you did not return owner.Value, it returns the object but not the object.Value