Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

HumanoidRootPart won't unanchor for some reason?

Hi, I'm trying to make an ability for a sword, where it creates a bubble, and when people walk into it, they freeze. Then after, they unfreeze. The thing is, though, the player doesn't unfreeze for some reason, but the code before it does run? Help would be much appreciated.

Here is the code:

local Damage = 5

local TweenService = game:GetService("TweenService")

local frozen = Instance.new("BoolValue")
frozen.Name = "Frozen"
frozen.Value = false

game.ReplicatedStorage.IceBoom.OnServerEvent:Connect(function(player)
	local char = player.Character
	local part = game.ServerStorage.Bubble
	local clone = part:Clone()

	local Tweeninformation = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)

	local TweenGoal = {Size = Vector3.new(47.333, 47.333, 47.333)}

	local TweenAnimation = TweenService:Create(clone,Tweeninformation,TweenGoal)
	
	local TweenGoal2 = {Size = Vector3.new(0.667, 0.667, 0.667)}

	local TweenAnimation2 = TweenService:Create(clone,Tweeninformation,TweenGoal2)
	
	clone.Parent = game.Workspace
	clone.Position = char.HumanoidRootPart.Position
	
	wait(.3)
	
	clone.Explosion:Play()
	clone.Ice:Play()
	
	wait(0.2)
	
	game.ReplicatedStorage.Boom:FireAllClients()
	TweenAnimation:Play()
	
	clone.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if hit.Parent.Name ~= player.Name then
				hit.Parent.HumanoidRootPart.Anchored = true
				frozen.Parent = hit.Parent
			end
		end
	end)
	
	local hit = 0
	
	while hit <= 5 do
		wait(1)
		hit = hit + 1
		for i,v in pairs(game.Players:GetPlayers()) do
			local char = v.Character
			if char:FindFirstChild("Frozen") then
				char.Humanoid:TakeDamage(Damage)
			end
		end
	end
		
	
	for i,v in pairs(game.Players:GetPlayers()) do
		local char = v.Character
		if char:FindFirstChild("Frozen") then
			char.Frozen:Destroy()
			char:FindFirstChild("HumanoidRootPart").Anchored = false
			print("Unanchored")
		end
	end
	TweenAnimation2:Play()
	wait(1)
	clone:Destroy()
end)

3 comments

0

Does it print "Unanchored"?

0

Yes.

0

It also says this for the error: "The Parent property of Frozen is locked, current parent: NULL, new parent Player1" Player1 is for when im doing the test with multiple players

1 answer

✓ Accepted answer

After doing a bit of research, the instance seems to be garbage-collected. Garbage collection is a process to clear up memory if it is no longer being used. A way to counter this is to parent the instance to an existing instance immediately.

6 comments

0

So like I parent it to the player's char immidiately? If so, that would made the script not work as intended. Sorry if I'm misunderstanding

0

You can parent it somewhere else, like ServerStorage.

0

Ok thanks, I'll try it!

0

I'm still getting the same error message. Is it because i still parent the value to the player after?

0

Can you tell me which line did the error told you? It should be telling you the line of scripts that broke. If you are able to, hit me up on Discord so that we can make messaging easier. Ayaya#3692 

0

sure! My user is The Gojira.

This discussion is preserved as it was. New answers, comments, and votes are closed.