local RepStorage = game:GetService("ReplicatedStorage")
print("WoodDropTest2")
local tween = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Root = char:WaitForChild("HumanoidRootPart")
local function playPopSound()
local popSound = script.Pop:Clone()
popSound.Parent = script
popSound:Play()
print("pop sound played")
popSound.Stopped:Connect(function()
popSound:Destroy()
end)
end
RepStorage.ToolFunctions.DestroyTree.OnClientEvent:Connect(function(tree)
print(tree.NumOfWoodDrops.Value)
print("WoodDropTest1")
for i = 1, tree.NumOfWoodDrops.Value do
print("looped")
local WoodDrop = RepStorage.WoodDrop:Clone()
WoodDrop.Parent = workspace
local treeCFrame = tree:GetPivot()
WoodDrop.CFrame = treeCFrame - Vector3.new(0, tree.PlusYFromFloor.Value, 0)
local randomX = math.random(WoodDrop.Position.X - 5, WoodDrop.Position.X + 5)
local randomZ = math.random(WoodDrop.Position.Z - 5, WoodDrop.Position.Z + 5)
local tweenRiseFinished = false
local tweenRise = tween:Create(WoodDrop, TweenInfo.new(0.25, Enum.EasingStyle.Cubic, Enum.EasingDirection.In), {Position = Vector3.new(randomX, WoodDrop.Position.Y + 4, randomZ)})
tweenRise:Play()
tweenRise.Completed:Connect(function()
tweenRiseFinished = true
WoodDrop.CanCollide = true
WoodDrop.Anchored = false
print("Hello")
end)
print("WoodDropTouchedTest")
WoodDrop.Touched:Connect(function(hit)
print("woodrop Touched")
if hit.Parent:IsDescendantOf(char) then
playPopSound()
RepStorage.GetWood.GetWood:FireServer(tree)
WoodDrop:Destroy()
end
end)
delay(0.2, function()
while not tweenRiseFinished do
wait()
local distance = (WoodDrop.Position - Root.Position).Magnitude
print(distance)
if distance > 10 then continue end
local tweenTowardsPlayer = tween:Create(WoodDrop, TweenInfo.new(0.05, Enum.EasingStyle.Cubic, Enum.EasingDirection.In), {Position = Root.Position})
tweenTowardsPlayer:Play()
tweenRise:Cancel()
tweenTowardsPlayer.Completed:Connect(function()
playPopSound()
RepStorage.GetWood.GetWood:FireServer(tree)
WoodDrop:Destroy()
end)
end
end)
end
end)
Everything works, but the touched function. When I touch the woodDrop “wooddrop touched” does not print or if anything touches it and I have no clue why.