How come repeat until doesnt seem to be working?

I am trying to make a script where once my werewolf dies it loops through all of my werewolf’s body parts and slowly makes them transparent but for some reason it isn’t working. heres my script

local repstorage = game:GetService("ReplicatedStorage")

local pos = script.Parent.HumanoidRootPart.Position

print(pos)

local clone = script.Parent:Clone()
clone.Parent = repstorage

script.Parent.Zombie.Died:Connect(function()
	clone.Parent = game.Workspace
	clone.Zombie.Health = clone.Zombie.MaxHealth
	clone:MoveTo(pos)
	local werewolf = script.Parent
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Part") or v:IsA("MeshPart") then
			repeat
				wait(0.1)
				v.Transparency = v.Transparency + 0.1
			until v.Transparency == 1
		end
	end
end)

oh and also there were no errors in the output and i know that repeat until can be very laggy so if you have any other alternatives for my script all help is appreciated.

Is it just because repeat until is or can be really laggy?

Just to let you know always use task.wait() instead of wait() because it works better.

Is there a specfic reason you’ve decided to not use TweenService for this? If not, I’d recommend scarping the loop method altogether and instead opting for TweenService. Here is an implementation of that below:

local TS = game:GetService("TweenService")
local TI = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) -- 5 means it will take 5 seconds for all the parts to fully have 1 transparency from its starting transparency 


for _, v in pairs(script.Parent:GetChildren()) do
	if v:IsA("BasePart") then -- this covers all parts by the way, meshparts as well as regular parts or anything else.
		TS:Create(v, TI, {Transparency = 1}):Play()
	end
end


4 Likes

Ohhhh sorry it was super late and my brain wasnt working properly lol. i completely forgot about tweens