Part not deleting when using :Destroy()

my part isn’t deleting when I use :Destroy() on it
I get nothing in output.

the part just doesn’t delete…

local script:

wait(2)

-- // SERVICES // --

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

-- // VARIABLES // --

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Event = ReplicatedStorage.AbilityEvents:WaitForChild("GuardShield")
local Hum = Character:WaitForChild("Humanoid")

-- // CHECK // --

repeat
	wait()
until
Character.Parent == workspace

-- // SCRIPT VARIABLES // --

local Holding = false
local Debounce = false

-- // SCRIPT // --

UIS.InputBegan:Connect(function(Input, gameProcessed)
	if not gameProcessed and Debounce == false and Hum.ragdoll.Value == false and not Hum.PlatformStand and Hum.Health > 0 then
		if Input.KeyCode == Enum.KeyCode.H and not Holding and not Debounce then
			Event:FireServer("Begin", Player)
			Debounce = true
			Holding = true
			while Holding and Character.Humanoid.WalkSpeed == 14 do
				wait()
			end
			print(Holding)
			wait(.5)
			if Holding == false then
				Event:FireServer("Finish", Player)
			end	
		end
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.H and Holding and Debounce then
		Holding = false
	--	Event:FireServer("Finish", Player)
		wait(5)
		Debounce = false
	end
end)

-- // EXTRA // --

ReplicatedStorage.ShieldCollisionOff.OnClientEvent:Connect(function()
	local shield = Player.Character:WaitForChild("GuardShield")
	shield.CanCollide = false
end)

server script:

-- // SERVICES // --

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- // VARIABLES // --

local Event = ReplicatedStorage.AbilityEvents:WaitForChild("GuardShield")
local Shield = game.Workspace:FindFirstChild("GuardShield")

-- // SCRIPT // --

Event.OnServerEvent:Connect(function(Player, Type)
	local Character = Player.Character
	if Type == "Begin" then
		local S = Shield:Clone()
		S.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-4)
--		S.Attachment.ParticleEmitter.Enabled = true
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = S
		weld.Part1 = Character.HumanoidRootPart
		weld.Parent = S
		game.ReplicatedStorage.ShieldCollisionOff:FireClient(Player)
		S.Orientation = Shield.Orientation
		S.Parent = Character
		S.Anchored = false
		Character.Humanoid.WalkSpeed = 14
	elseif Type == "Finish" then
		Player.Character.GuardShield:Destroy()
		Character.Humanoid.WalkSpeed = 16
	end
end)

is there any alternative method to remove the part that would work?

either do 3 things: use :remove(), set the parts parent to nil or use DebrisService:AddItem()

:Remove() did nothing. I will try setting the parent to nil or adding it to debrisservice

Remove() is deprecated and shouldnt be used.

Destroy() is faster than Debris:AddItem().

Why are you doing Player.Character if you’ve already defined Character?

Setting the parent to nil did nothing…

adding the part to DebrisService also did nothing

I changed it so I use the character instead of player.character

Try to print out Character.GuardShield on the server call within the remote

First, these suggestions are brain corrupting.
Use a basic print to see whether the if statement is actually working. Then you can determine which lines are failing.

Then you can go from there.

1 Like

Try to print out Character.GuardShield on the server call within the remote and see if it exists and if not - it means you either need to use WaitForChild or check if lines above are valid.

I printed “Found” if GuardShield was inside the character and it didn’t print

however the part IS inside my character as I can see it in explorer

Also, you should use PivotTo() instead, just make sure your model has a primary part.

1 Like

I just looked out your output. The variable holding is printed as true. That’s why the event didn’t fire in the first place.

1 Like
-- // SERVICES // --

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- // VARIABLES // --

local Event = ReplicatedStorage.AbilityEvents:WaitForChild("GuardShield")
local Shield = game.Workspace:FindFirstChild("GuardShield")

-- // SCRIPT // --

local S = nil

Event.OnServerEvent:Connect(function(Player, Type)
	local Character = Player.Character
	if Type == "Begin" then
		S = Shield:Clone()
		S.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-4)
--		S.Attachment.ParticleEmitter.Enabled = true
		local weld = Instance.new("WeldConstraint")
		weld.Part0 = S
		weld.Part1 = Character.HumanoidRootPart
		weld.Parent = S
		game.ReplicatedStorage.ShieldCollisionOff:FireClient(Player)
		S.Orientation = Shield.Orientation
		S.Parent = Character
		S.Anchored = false
		Character.Humanoid.WalkSpeed = 14
	elseif Type == "Finish" then
		S:Destroy()
		Character.Humanoid.WalkSpeed = 16
	end
end)

???

the shield isn’t a model. it’s a part with an attachment inside it with a particle emitter in the attachment

yes however “false” should be printed when i stop holding and it’s not

why did you set S as nil?
i clone the shield in the onserverevent function, that is S
S isnt carried after the “elseif” for some reason

idk why I set it as nil knowing I could by leaving it empty like this local S
make S a global variable or perhaps add it in a table. and remove the first member of le table.

I made S a global variable but “false” still doesnt print and neither does “found” so i don’t see how it would make a difference when trying to destroy the part

I have one last trick… use for i,v loops to see IF something called “GuardShield” exists destroy it.