-
What do you want to achieve?
make it so parts are able to be cut -
What is the issue?
Code Just Decides To Self Destruct
-
What solutions have you tried so far?
i tried making it so if 1 of the parts are nil the other one gets destroyed
local cooldown = false
local toolcooldown = false
script.Parent.Activated:Connect(function()
if toolcooldown == false then
toolcooldown = true
script.Parent.Handle.ParticleEmitter.Enabled = true
script.Parent.Trail.Enabled = true
local slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.HeavySlash)
slash.Looped = false
slash:Play()
script.Parent.Blade.CanTouch = true
wait(0.75)
script.Parent.Trail.Enabled = false
wait(0.25)
script.Parent.Trail.Enabled = true
wait(1)
script.Parent.Trail.Enabled = false
script.Parent.Blade.CanTouch = false
wait(2)
toolcooldown = false
end
end)
script.Parent.Blade.Touched:Connect(function(hit)
local humanoid = hit:FindFirstChild("Breakable")
if humanoid ~= nil and cooldown == false then
print(hit)
cooldown = true
local hitclone = hit:Clone()
hitclone.Position = hit.Position
print(hitclone)
hitclone.Parent = game.Workspace
local negative = game.ReplicatedStorage.CuttingZone:Clone()
negative.Parent = game.Workspace
negative.CutPivot.Orientation = Vector3.new(0,0,math.random(1,360))
negative.CutPivot.Position = hit.Position
negative.CutPivot.NegativePart1.Anchored = true
negative.CutPivot.NegativePart2.Anchored = true
local negative1 = negative.CutPivot.NegativePart1
local negative2 = negative.CutPivot.NegativePart2
local pivot = negative.CutPivot
negative1.CFrame = pivot.Attachment.WorldCFrame * negative1.Attachment.CFrame:Inverse()
negative2.CFrame = pivot.Attachment.WorldCFrame * negative2.Attachment.CFrame:Inverse()
negative1.Parent = game.Workspace
negative2.Parent = game.Workspace
pivot:Destroy()
negative:Destroy()
local union1 = hitclone:SubtractAsync({negative1})
local union2 = hit:SubtractAsync({negative2})
local breakable1 = Instance.new("BoolValue")
local breakable2 = Instance.new("BoolValue")
breakable1.Name = "Breakable"
breakable2.Name = "Breakable"
union1.Parent = game.Workspace
union2.Parent = game.Workspace
union1.Name = "Union1"
union2.Name = "Union2"
union1.Parent = game.Workspace
union2.Parent = game.Workspace
hitclone:Destroy()
hit:Destroy()
negative1:Destroy()
negative2:Destroy()
union1.Anchored = false
union2.Anchored = false
breakable1.Parent = union1
breakable2.Parent = union2
union2.UsePartColor = true
union1.UsePartColor = true
cooldown = true
wait(1)
cooldown = false
end
end)