RootPart won't unanchor

I’m trying to make a hammer that unanchors anchored part when hit. This is my script and it doesn’t work.

Attempt 1:

local tool = script.Parent
local head = tool.Handle

local remoteEvent = tool.RemoteEvent

local smash

remoteEvent.OnServerEvent:Connect(function(player, character, charged, magnitude)
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	if charged then
		smash = head.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			local hitCharacter = hit.Parent
			local hitRootPart = hitCharacter:WaitForChild("HumanoidRootPart")
						
			if humanoid then	
				local knockback = Instance.new("BodyVelocity")
				
				hitRootPart.Anchored = false --here
				
				knockback.Parent = hitRootPart
				knockback.Velocity = (rootPart.CFrame.LookVector * magnitude) + (rootPart.CFrame.UpVector * magnitude)
				knockback.MaxForce = knockback.MaxForce * magnitude
				wait()
				knockback:Destroy()
			end
		end)
		
		wait(0.3)
		smash:Disconnect()
	end
end)

Attempt 2:

local tool = script.Parent
local head = tool.Handle

local remoteEvent = tool.RemoteEvent

local smash

remoteEvent.OnServerEvent:Connect(function(player, character, charged, magnitude)
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	if charged then
		smash = head.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			local hitCharacter = hit.Parent
			local hitRootPart = hitCharacter:WaitForChild("HumanoidRootPart")
			
			if humanoid then
				if hitRootPart.Anchored == true then
					hitRootPart.Anchored = false --here
				end
				
				local knockback = Instance.new("BodyVelocity")
				
				knockback.Parent = hitRootPart
				knockback.Velocity = (rootPart.CFrame.LookVector * magnitude) + (rootPart.CFrame.UpVector * magnitude)
				knockback.MaxForce = knockback.MaxForce * magnitude
				wait()
				knockback:Destroy()
			end
		end)
		
		wait(0.3)
		smash:Disconnect()
	end
end)

Attempt 3:

local tool = script.Parent
local head = tool.Handle

local remoteEvent = tool.RemoteEvent

local smash

remoteEvent.OnServerEvent:Connect(function(player, character, charged, magnitude)
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	if charged then
		smash = head.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			local hitCharacter = hit.Parent
			local hitRootPart = hitCharacter:WaitForChild("HumanoidRootPart")
			
			if hitRootPart.Anchored == true then
				hitRootPart.Anchored = false --here
			end
			
			if humanoid then	
				local knockback = Instance.new("BodyVelocity")
				
				knockback.Parent = hitRootPart
				knockback.Velocity = (rootPart.CFrame.LookVector * magnitude) + (rootPart.CFrame.UpVector * magnitude)
				knockback.MaxForce = knockback.MaxForce * magnitude
				wait()
				knockback:Destroy()
			end
		end)
		
		wait(0.3)
		smash:Disconnect()
	end
end)
2 Likes

I don’t see an issue with any of those 3 attempts, even though they’re a bit weirdly setup, so some things that may be the issue:

maybe you’re anchoring the HumanoidRootPart on clientside (localScript), so according to serverside (this script), it’s still unanchored and nothing will change

maybe you’re sending the wrong values through the remote, you started each function with rootPart = character:WaitForChild("HumanoidRootPart"), if character isn’t a character model, this will infinitely yield, try checking the output for warnings of this

maybe magnitude is too little that even after unanchoring, you’ve set the velocity to something like 0,0,0 and it won’t move

1 Like

so i have 2 dummies. one of them’s rootpart is anchored while the other one is not. the unanchored one works and the anchored isnt. so im assuming that my attempts dont really unanchored the rootpart.

no warnings for infinite yields either?
try adding prints or breakpoints around, maybe the remote isn’t being fired properly

its fine now i just unanchored the hitrootpart after local knockback. thanks btw

nvm it doesnt work ;-; what the heck

add
Character.Archivable = true

so like hitCharacter.Archivable = true
maybe

1 Like
local tool = script.Parent
local head = tool.Handle

local remoteEvent = tool.RemoteEvent

local smash

remoteEvent.OnServerEvent:Connect(function(player, character, charged, magnitude)
	local rootPart = character:WaitForChild("HumanoidRootPart")
	
	if charged then
		smash = head.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			local hitCharacter = hit.Parent
			local hitRootPart = hitCharacter:FindFirstChild("HumanoidRootPart")
			
			if humanoid then
				local knockback = Instance.new("BodyVelocity")
				
				hitCharacter.Archivable = true
				hitRootPart.Anchored = false
				
				knockback.Parent = hitRootPart				
				knockback.Velocity = (rootPart.CFrame.LookVector * magnitude) + (rootPart.CFrame.UpVector * magnitude)
				knockback.MaxForce = knockback.MaxForce * magnitude
				wait()
				knockback:Destroy()
			end
		end)
		
		wait(0.3)
		smash:Disconnect()
	end
end)

like this??

Yeah. Looks like it, try it now

did it fix your problem?


YO YES IT DID thanks man but would u mind explaining how Archivable = true actually fixed the problem? It would be appreciated.

normally the character’s properties cant be changed so by turning archivable on it allowed the script to change the character’s properties

2 Likes

ohhhh i see thanks again brother