Even tho I write for the part to get unchored, it does not work. I already checked and searched, but I haven’t find the problem yet.
Full Script
local Tool = script.Parent
local AXE_POWER = 22
local TotalCountdown = 2
local Countdown = 0
Tool.Activated:Connect(function()
--Countdown
if Countdown ~= 0 then
return
end
print("Axe hit: " .. AXE_POWER)
Countdown = TotalCountdown
task.spawn(function()
while Countdown > 0 do
wait(1)
Countdown -= 1
end
end)
local HumanoidRootPart = Tool.Parent:FindFirstChild("HumanoidRootPart")
--Hitbox Spawn
local hitbox = Instance.new("Part")
hitbox.Size = Vector3.new(5, 5, 5)
hitbox.Transparency = .5
hitbox.BrickColor = BrickColor.Red()
local hitboxClone = hitbox:Clone()
hitboxClone.Parent = workspace
hitboxClone.CanCollide = false
hitboxClone.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -4)
task.spawn(function()
task.wait(1)
if hitboxClone then
hitboxClone:Destroy()
end
end)
--Hitting Tree
local hit = workspace:GetPartBoundsInBox(HumanoidRootPart.CFrame * CFrame.new(0, 0, -4), Vector3.new(5, 5, 5))
local Tree
local Wood
local TreeHealth
for _, part in ipairs(hit) do
if part.Name == "Wood" then
Tree = part.Parent
Wood = Tree:FindFirstChild("Wood")
TreeHealth = Tree:FindFirstChild("HealthValue")
if Wood and TreeHealth then
--Sound
task.spawn(function()
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://8394333801"
local PitchEffect = Instance.new("PitchShiftSoundEffect")
local PitchEffectClone = PitchEffect:Clone()
local SoundClone = Sound:Clone()
PitchEffectClone.Parent = SoundClone
PitchEffectClone.Octave = math.random(99, 111) / 100
SoundClone.Parent = part
SoundClone:Play()
SoundClone.Ended:Connect(function()
SoundClone:Destroy()
end)
end)
break
end
end
end
--Check Tree Health
if TreeHealth == nil then return end
TreeHealth.Value -= AXE_POWER
if TreeHealth.Value <= 0 then
for _, part in Tree:GetChildren() do
if part:IsA("Part") then
part.Anchored = false
Wood.CanCollide = false
end
end
local wood = Instance.new("Part")
wood.Color = Wood.Color
wood.Size = Vector3.new(1, 1, 3)
wood.Material = Enum.Material.Wood
wood.Position = Wood.Position
wood.Anchored = false
wood.Parent = workspace
end
end)
Line that might be the problem:
for _, part in Tree:GetChildren() do
if part:IsA("Part") then
part.Anchored = false
Wood.CanCollide = false
end
end
local wood = Instance.new("Part")
wood.Color = Wood.Color
wood.Size = Vector3.new(1, 1, 3)
wood.Material = Enum.Material.Wood
wood.Position = Wood.Position
wood.Anchored = false
wood.Parent = workspace