Destroy() Causing Weird Player Acceleration

Hi, I have recently started working on a new project and for a hitbox I have been using a part and GetTouchingParts() function. However after I spawn in the part and promptly destroy it there is still a weird physics effect were the player will gain a lot of velocity when turning as if the block was still there? Is there a way to remove it or am I just forgetting something? This is my code

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Animation = script:WaitForChild("Fall")
local debounce = false


ReplicatedStorage.AttackHitboxOne.OnServerEvent:Connect(function(player)
	if debounce == false then
		debounce = true
		local Humanoid = player.Character.Humanoid
		
			if Humanoid.FloorMaterial ~= Enum.Material.Air then
				local part = Instance.new("Part")
				local offset = Vector3.new(0, 0, -5)
				part.Size = Vector3.new(10,12,15)
				part.Transparency = 1
				part.Name = "Fall Hitbox"
				part.CanCollide = true
				part.Anchored = true
				part.Parent = workspace
				part.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(offset)
				player.Character.HumanoidRootPart.Anchored = true
				local Anim = Humanoid:LoadAnimation(Animation)
				Anim:Play()
				wait(0.4)
				for _, touching in pairs(part:GetTouchingParts()) do
				if touching.Parent then
					if touching.Parent.Name:match("Enemy") then
						if not touching.Parent:FindFirstChild("AttackScript") then
							touching.Parent:Destroy()
						end
					end
				end		
			end
		wait(0.4)
		Anim:Stop()
		player.Character.HumanoidRootPart.Anchored = false
		part:Destroy()
		end
	end
	debounce = false
end)

turn cancollide to off

you can still do queries as long as canquery or cantouch is on

It doesnt work with cancollide off and even with that the bug still persists

In the Instance:Destroy() documentation:

It says

As a best practice after calling Destroy() on an object, set any variables referencing the object (or its descendants) to nil. This prevents your code from accessing anything to do with the object.

Maybe try setting the part to nil and see if it works

I inserted the line part = nil before and after the destroy() line but it still persisted is there a different spot I should put it or is this just not the solution for my circumstance

if it does not work then yes the solution is something else. Worth a try though

You could also try setting the offset back to Vector3.new(0,0,0)

Or you can try setting the other instances to nil or set the property to ita default settings

These might not work but its worth a shot

Unfortunately that didnt work I also tried entirely rewriting it into a client sided script but the bug still persisted the only thing I’ve been able to narrow it down to is that the block is still affecting velocity as if it were attached but I have no idea how to destroy it any further than I already have. Thank you though

The problem was actually in the animation no idea what it was but a slight change fixed it thanks for the help though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.