Problem with "freezing" a player in place

So i’ve been trying to freeze a player in place when they touch a part, then unfreeze, the first part works fine, the player is frozen in place and their skin color is changed to have the frozen look, the problem lands when i try to “defrost” the player, by just unanchoring their limbs, wich although it does work, for one, the skin color change is not applied, and two, the character is technically anchored, but their limbs still move doing the walk animation, and THEN it is unchanchored, so although it works, i want to find a way that - changes the skin color to the color i want it to be - the character stays in place without moving their limbs from their walk animation or any animation in general, just completely static -

i can’t record, but i provided these images to show how it works

  • first image is the script without task.wait(1) limb.anchored = false, it works perfectly fine

  • second image is the same script but with task.wait(1) limb.anchored = false

  • third image is the continuation of the second image, it applies the skin color change and after a few seconds the animations start bugging all over the place

imagen_2024-06-30_153127002
imagen_2024-06-30_153257488
imagen_2024-06-30_153321750

Here is my code:

local part = script.Parent

part.Touched:Connect(function(hit)
	local player = hit.Parent
	if player and player:IsA("Model") then
		local humanoid = player:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid:TakeDamage(10)
			for i, limb in player:GetChildren() do
				if limb:IsA("BasePart") then
					limb.Anchored = true
					limb.Color = Color3.fromRGB(116, 255, 227)
					-- task.wait(1)
					-- limb.Anchored = false
				end
			end
		end
	end
end)

Thanks in advance for the help!

2 Likes

the task.wait(1) is holding up the whole loop, so its doing one limb, waiting a second then another and so on, try this:

local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
	local player = hit.Parent
	if player and player:IsA("Model") then
		local humanoid = player:FindFirstChildOfClass("Humanoid")
		if humanoid and debounce == false then
			debounce = true
			humanoid:TakeDamage(10)
			for i, limb in player:GetChildren() do
				if limb:IsA("BasePart") then
					limb.Anchored = true
					limb.Color = Color3.fromRGB(116, 255, 227)
				end
			end

			task.wait(1)

			for i, limb in player:GetChildren() do
				if limb:IsA("BasePart") then
					limb.Anchored = false
-- more stuff
				end
			end
			task.wait(2) -- change this to whatever the cooldown you want it to be
			debounce = false
		end
	end
end)

i also added a cooldown so its not repeadetly firing the script when touched

1 Like

works like a dream, thank you!

1 Like

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