So I have a tool that whenever the handle touches the Box or Tree Stump part, you can get a random tool from the box and a bundle of wood from the tree. However, the wood bundle does not position itself at the WoodSpawn part. The wood bundle is a model with its Primary Part set to Primary.
Client:
local tool = script.Parent
local Handle = tool.Handle
local Player = game.Players.LocalPlayer
local BoxMaxHealth = 250
local TreeMaxHealth = 500
local TargetRotation = CFrame.Angles(math.rad(-90), 0, 0)
local info = TweenInfo.new(
1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local TreeTween = game:GetService("TweenService"):Create(workspace.Tree.PrimaryPart, info, {CFrame = workspace.Tree.PrimaryPart.CFrame * TargetRotation})
local function CheckAndDamageBox(hit)
local Box = workspace:FindFirstChild("Box")
if Box and hit.Name == "Box" and hit.BillboardGui then
local BoxHealth = Box.BoxHealth
BoxHealth.Value -= 50
Box.Hit:Play()
Box.BillboardGui.TextLabel.Text = BoxHealth.Value.."/"..BoxMaxHealth
if BoxHealth.Value <= 0 then
script.BreakSound:Play()
Box:Destroy()
game.ReplicatedStorage.ItemEvent:FireServer(Player)
end
end
end
local function CheckAndDamageTree(hit)
local Tree = workspace:FindFirstChild("Tree")
if Tree and hit.Name == "Stump" and hit.Parent.BillboardGui then
local TreeHealth = Tree.TreeHealth
TreeHealth.Value -= 50
Tree.HitWood:Play()
Tree.BillboardGui.TextLabel.Text = TreeHealth.Value.."/"..TreeMaxHealth
if TreeHealth.Value <= 0 then
script.Fall:Play()
TreeTween:Play()
task.wait(1.4)
Tree:Destroy()
game.ReplicatedStorage.GiveWood:FireServer(Player)
end
end
end
Handle.Touched:Connect(function(hit)
CheckAndDamageBox(hit)
CheckAndDamageTree(hit)
end)
Server:
local Items = game.ReplicatedStorage.Items
local Box = workspace.Box
local ItemSpawn = Box.ItemSpawn
game.ReplicatedStorage.ItemEvent.OnServerEvent:Connect(function(Player)
local RandomNumber = math.random(1, 3)
if RandomNumber == 1 then
local BloxyCola = Items.BloxyCola:Clone()
BloxyCola.Parent = workspace
BloxyCola.Handle.Position = ItemSpawn.Position
elseif RandomNumber == 2 then
local ClassicSword = Items.ClassicSword:Clone()
ClassicSword.Parent = workspace
ClassicSword.Handle.Position = ItemSpawn.Position
elseif RandomNumber == 3 then
local OnionRing = Items.OnionRing:Clone()
OnionRing.Parent = workspace
OnionRing.Handle.Position = ItemSpawn.Position
end
end)
game.ReplicatedStorage.GiveWood.OnServerEvent:Connect(function(Player)
local WoodBundle = game.ReplicatedStorage.WoodBundle:Clone()
WoodBundle.PrimaryPart.Position = workspace.WoodSpawn.Position
WoodBundle.Parent = workspace
print("placed")
end)
If you think you know what went wrong, please let me know. Thank you and have a wonderful day!