Make a random model to unanchor

i want a random model to be chosen from the model FallenTrees and set anchored and cancollide to false

local trees = {
	script.Parent.FalledTrees.tree1,
	script.Parent.FalledTrees.tree2
}

script.Parent.detector.Touched:Connect(function(hit)
	game.ReplicatedStorage.events.detected:Fire(hit)

	local r = trees[math.random(1, #trees)]
	r:GetDescendants().Anchored = false
	r:GetDescendants().CanCollide = false
	task.wait(3)
	r:Destroy()
end)

but it isnt working
also the :Destroy() Destroys everything in the table

1 Like
for _,v in model:getDescendants() do
if v:IsA("BasePart") then
v.Anchored = false
v.CanCollide = false
end
end

This is an example, code the rest and fill in the unknown variables yourself. You have to loop through the descendants, as it returns a table. A table does not have the Anchored or CanCollide property and that is what your code is trying to set.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.