Destroy character's HumanoidRootPart script not working

I have this script that is supposed remove a characters HumanoidRootPart whenever they touch it, but it doesn’t work. This is the Output.


Also here’s the script.

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		local char = game.Workspace.CharlotteOfficeDoor(hit.Parent)
		if char == nil or char.CharlotteOfficeDoor:FindFirstChild("HumanoidRootPart") == nil then return end
		char.CharlotteOfficeDoor.HumanoidRootPart:Destroy()
		debounce = false
	end
end)
1 Like

Line 6 Your attempting to call a method on a instance value which will not work. I’m guessing your trying to get the character so you should just do

		local char = hit.Parent
1 Like

Since accessory models are parented to their Accessory object and not the character, this method is no longer viable (although enviously simple :frowning:.)

The best practice that will give you the least issues currently is using FindFirstAncestorOfClass on your hit part to find the ancestor Model, then using Players:GetPlayerFromCharacter(ancestorModel) to confirm that your model belongs to a player and as such means it is a character.

I wish it was still this easy but using hit.Parent will give you inconsistent results. Cheers!

2 Likes

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