I want a shirt and pants to change color to black gradually with “for loop”, but when i touch the trigger shirt changes color to black instantly and same applies to pants. Any ideas how to fix it?
code:
local part = script.Parent
local beata = game.Workspace:WaitForChild("Beata11")
local shirt = beata:FindFirstChildOfClass("Shirt")
local pants = beata:FindFirstChildOfClass("Pants")
local ShirtColor = shirt.Color3
local PantsColor = pants.Color3
local flag = true
local function PantsBlacken()
local newColor = PantsColor
while newColor.r > 0 or newColor.g > 0 or newColor.b > 0 do
newColor = Color3.new(newColor.r - 1, newColor.g - 1, newColor.b - 1)
pants.Color3 = newColor
task.wait(0.5) -- wait for 0.5 seconds
end
end
local function ShirtBlacken()
local newColor = ShirtColor
while newColor.r > 0 or newColor.g > 0 or newColor.b > 0 do
newColor = Color3.new(newColor.r - 1, newColor.g - 1, newColor.b - 1)
shirt.Color3 = newColor
task.wait(0.5) -- wait for 0.5 seconds
end
end
part.Touched:Connect(function(hit)
local char = hit.Parent
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(char)
local hum = char:FindFirstChildOfClass("Humanoid")
if hum and player and flag then
flag = not flag
print(char.Name .. "touched part")
ShirtBlacken()
PantsBlacken()
end
end)