Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --services
- local rs = game:GetService("ReplicatedStorage")
- --modules
- local treeInfo = require(script.treeInfo)
- --variables
- local cutThickness = script.variables.cutThickness.Value
- local tooClose = script.variables.tooClose.Value
- --events
- local events = rs.events
- local cutEvent = events.chop
- local axe = {}
- --functions
- local function Split(target, mouse, cut)
- local top = target.CFrame * CFrame.new(0, target.Size.Y / 2, 0) * CFrame.Angles(math.pi / 2, 0, 0)
- local bottom = target.CFrame * CFrame.new(0, target.Size.Y / -2, 0) * CFrame.Angles(math.pi / -2, 0, 0)
- local part0 = Instance.new("Part", target.Parent)
- part0.Size = Vector3.new(target.Size.X, (top.Position - cut.Position).Magnitude, target.Size.Z)
- part0.Color = target.Color
- part0.Material = target.Material
- part0.CFrame = target.CFrame + target.CFrame.UpVector * (top.Position - cut.Position).Magnitude
- local part1 = Instance.new("Part", target.Parent)
- part1.Size = Vector3.new(target.Size.X, (bottom.Position - cut.Position).Magnitude, target.Size.Z)
- part1.Color = target.Color
- part1.Material = target.Material
- part1.CFrame = target.CFrame + target.CFrame.UpVector * -(bottom.Position - cut.Position).Magnitude
- for i, v in pairs(target:GetChildren()) do
- v:Destroy()
- end
- target:Destroy()
- end
- function PlaceCut(target, mouse)
- local top = target.CFrame * CFrame.new(0, target.Size.Y / 2, 0) * CFrame.Angles(math.pi / 2, 0, 0)
- local bottom = target.CFrame * CFrame.new(0, target.Size.Y / -2, 0) * CFrame.Angles(math.pi / -2, 0, 0)
- local cutsFolder = target.cuts
- local cut = Instance.new("Part", cutsFolder)
- cut.Size = Vector3.new(target.Size.X + 0.01, cutThickness, target.Size.Z + 0.01)
- cut.Color = Color3.new(0,0,0)
- cut.CFrame = target.CFrame
- cut.Massless = true
- cut.CanCollide = false
- cut.Name = "cut"
- local distance = (target.Position - mouse).magnitude
- if (top.Position-mouse).Magnitude >= (bottom.Position-mouse).Magnitude then
- distance = -distance
- end
- cut.CFrame = target.CFrame + target.CFrame.UpVector * distance
- local weld0 = Instance.new("WeldConstraint", cut)
- weld0.Part0 = cut
- weld0.Part1 = target
- task.wait(1)
- Split(target, mouse, cut)
- end
- function CheckCut(target, mouse)
- local top = target.CFrame * CFrame.new(0, target.Size.Y / 2, 0) * CFrame.Angles(math.pi / 2, 0, 0)
- local bottom = target.CFrame * CFrame.new(0, target.Size.Y / -2, 0) * CFrame.Angles(math.pi / -2, 0, 0)
- local cutsFolder = target:FindFirstChild("cuts") or Instance.new("Folder", target)
- cutsFolder.Name = "cuts"
- local canCut = true
- for i, v in pairs(cutsFolder:GetChildren()) do
- local distance = (v.Position - mouse).magnitude
- if distance <= tooClose or top.position <= tooClose or bottom.position <= tooClose then
- canCut = false
- end
- end
- if canCut then
- PlaceCut(target, mouse)
- else
- print("too close")
- end
- end
- --connections
- cutEvent.OnServerEvent:Connect(function(player, target, mouse)
- CheckCut(target, mouse)
- end)
- return axe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement