So in my game, I have a ZA HANDO stando, and what it does, is if it touches a part, it will destroy it. But what I’ve found is that it works, but only once. I tried using different things to try and show that the part is gone, for example, :Destroy(), :Remove(), and turning its cancollide to false, and changing its transparency to 1, and etc. But it still only either works once, or doesn’t work at all. The line on which I try to destroy the part is 54, and 55. Someone please help.
Here is the code:
local rp = game:GetService("ReplicatedStorage")
local Punch = rp:WaitForChild("Stand4Remotes"):WaitForChild("Punch")
local Debris = game:GetService("Debris")
local damage = 15
local currentAtk = 0
Punch.OnServerEvent:Connect(function(Player)
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local Stand = workspace:FindFirstChild(Player.Name.." Stand"):WaitForChild("Dummy")
local folder = Instance.new("Folder",workspace)
folder.Name = Player.Name.." Stand Punch"
Debris:AddItem(folder,.5)
if Stand then
currentAtk = currentAtk + 1
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(0,-.5,-2)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
if currentAtk == 1 then
local Hand = Stand:WaitForChild("LeftHand")
local animControl = Stand:WaitForChild("AnimControl")
local Punch = animControl:LoadAnimation(script:WaitForChild("LeftPunch"))
Punch:Play()
local HitBox = script:WaitForChild("HitBox"):Clone()
HitBox.CFrame = Hand.CFrame
HitBox.Parent = folder
local Pweld = Instance.new("Weld")
Pweld.Part0 = HitBox
Pweld.Part1 = Hand
Pweld.C0 = HitBox.CFrame:inverse() * Hand.CFrame
Pweld.Parent = Pweld.Part0
HitBox.Touched:Connect(function(Hit)
if Hit:IsA("Part") or Hit:IsA("MeshPart") then
Hit.CanCollide = false
Hit.Transparency = 1
if Hit.Parent ~= Character then
local EHumRP = Hit.Parent:FindFirstChild("HumanoidRootPart")
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
HitBox:Destroy()
local sound = Instance.new("Sound",folder)
sound.SoundId = "rbxassetid://2174934844"
sound.Volume = 1
sound:Play()
Debris:AddItem(sound,.5)
if Humanoid.Health > 0 then
local vel = Instance.new("BodyVelocity",EHumRP)
vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
Humanoid:TakeDamage(15)
if Humanoid.Health < 1 then
Player.leaderstats.Kills.Value = Player.leaderstats.Kills.Value + 1
Player.leaderstats.moneys.Value = Player.leaderstats.moneys.Value + 50
end
end
end
end
end
end)
wait(.5)
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(2,0,2)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
elseif currentAtk == 2 then
local Hand = Stand:WaitForChild("RightHand")
local animControl = Stand:WaitForChild("AnimControl")
local Punch = animControl:LoadAnimation(script:WaitForChild("RightPunch"))
Punch:Play()
local HitBox = script:WaitForChild("HitBox"):Clone()
HitBox.CFrame = Hand.CFrame
HitBox.Parent = folder
local Pweld = Instance.new("Weld")
Pweld.Part0 = HitBox
Pweld.Part1 = Hand
Pweld.C0 = HitBox.CFrame:inverse() * Hand.CFrame
Pweld.Parent = Pweld.Part0
HitBox.Touched:Connect(function(Hit)
if Hit:IsA("Part") or Hit:IsA("MeshPart") then
if Hit.Parent ~= Character then
local EHumRP = Hit.Parent:FindFirstChild("HumanoidRootPart")
local EHumanoid = Hit.Parent:FindFirstChild("Humanoid")
if EHumanoid then
HitBox:Destroy()
local sound = Instance.new("Sound",folder)
sound.SoundId = "rbxassetid://2174934844"
sound.Volume = 1
sound:Play()
Debris:AddItem(sound,.5)
if EHumanoid.Health > 0 then
local vel = Instance.new("BodyVelocity",EHumRP)
vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
vel.Velocity = HumanoidRP.CFrame.lookVector * 3.5
Debris:AddItem(vel, 1)
EHumanoid:TakeDamage(damage)
if EHumanoid.Health < 1 then
Player.leaderstats.Kills.Value = Player.leaderstats.Kills.Value + 1
Player.leaderstats.moneys.Value = Player.leaderstats.moneys.Value + 50
end
end
end
end
end
end)
wait(.5)
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(2,0,2)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
else
currentAtk = 1
local Hand = Stand:WaitForChild("LeftHand")
local animControl = Stand:WaitForChild("AnimControl")
local Punch = animControl:LoadAnimation(script:WaitForChild("LeftPunch"))
Punch:Play()
local HitBox = script:WaitForChild("HitBox"):Clone()
HitBox.CFrame = Hand.CFrame
HitBox.Parent = folder
local Pweld = Instance.new("Weld")
Pweld.Part0 = HitBox
Pweld.Part1 = Hand
Pweld.C0 = HitBox.CFrame:inverse() * Hand.CFrame
Pweld.Parent = Pweld.Part0
HitBox.Touched:Connect(function(Hit)
if Hit:IsA("Part") or Hit:IsA("MeshPart") then
if Hit.Parent ~= Character then
local EHumanoid = Hit.Parent:FindFirstChild("Humanoid")
if EHumanoid then
HitBox:Destroy()
local sound = Instance.new("Sound",folder)
sound.SoundId = "rbxassetid://2174934844"
sound.Volume = 1
sound:Play()
Debris:AddItem(sound,.5)
local EHumRP = Hit.Parent:FindFirstChild("HumanoidRootPart")
if EHumanoid.Health > 0 then
local vel = Instance.new("BodyVelocity",EHumRP)
vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
vel.Velocity = HumanoidRP.CFrame.lookVector * 0.8
Debris:AddItem(vel, 1)
EHumanoid:TakeDamage(damage)
if EHumanoid.Health < 1 then
Player.leaderstats.Kills.Value = Player.leaderstats.Kills.Value + 1
Player.leaderstats.moneys.Value = Player.leaderstats.moneys.Value + 50
end
end
end
end
end
end)
wait(.5)
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(2,0,2)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
end
end
end)