Why doesnt my script unanchor my player?

Basically I have a problem where when my character touches a block it gets anchored then unanchored but it doesn’t seem to work

local IceBlock = Instance.new("Part")
IceBlock.Name = "Ice"
IceBlock.Anchored = true
IceBlock.BrickColor = BrickColor.new("ToothPaste")
IceBlock.Transparency = 0.5
IceBlock.Size = Vector3.new(5,7,5)

local function Freeze(character,Bool)
for _,CharacterPart in pairs(character:GetChildren()) do
if CharacterPart:IsA("BasePart") then
CharacterPart.Anchored = Bool
end
end
end


script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Dealer") == nil and hit.Parent:FindFirstChild("Hurt") == nil then

local char = hit.Parent

local hurtbool = Instance.new("BoolValue",char)
hurtbool.Name = "Hurt"
game.Debris:AddItem(hurtbool,4)

char:FindFirstChild("Humanoid"):TakeDamage(40)
char.Archivable = true

local IceBlockClone = IceBlock:Clone()
IceBlockClone.Parent = game.Workspace
IceBlockClone.CFrame = char.HumanoidRootPart.CFrame

Freeze(char,true)
wait(4)
Freeze(char,false)

end
end)
1 Like

IceBlock.Name == “Ice”

and

hurtbool.Name == “Hurt”

Those should only be one equal sign. That’s what sticks out to me first.

1 Like

The same outcome happens where the player gets anchored but doesn’t get unanchored.

I tested it in studio, and the issue is that once the character hits the “ice block” and then becomes unachored, the Touched event fires right away as the character inevitably touches it again. You should add a debounce or cooldown between when they can be frozen again

ah for what I did instead of it touching a part its an attack and the touch part automatically deletes, the hurt bool prevents multiple touched events firing

oh I see. The issue I believe is then the deleting. Once you delete the part, you also delete the script which never allows the Freeze(char, false) to fire.

Oh that might be the reason, ill try it out

thank you for your support, it worked