I want a part that fades off for 1 second, then turns the CanCollide off.
After the transparency turns all the way off, the CanCollide stays for about 0.1 seconds.
I have tried updating the blocks physics using AssemblyLinearVelocity, changing logic, etc. Nothing seems to work.
ServerScriptService code:
for _, v in pairs(game.Workspace.Model:GetChildren()) do
if v:IsA("BasePart") then
task.spawn(function()
v.Touched:Connect(function()
if v.Parent:FindFirstChildOfClass("Humanoid") then
for i = 1, 9 do
v.Transparency += 0.1
task.wait(0.1)
end
v.Transparency += 0.1
v.CanCollide = false
end
end)
end)
end
end
I think it may be something to do with the for loop and multiple events firing since you keep touching the part. Tweening works better for me, as well as disabling the CanTouch property as soon as the event fires. Be sure to re-enable CanTouch if you want the Touched event to be able to fire again later.
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine) -- Time to completion and easing style.
local tweenGoal = {Transparency = 1} -- Properties and the wanted values.
for _, v in pairs(game.Workspace.Model:GetChildren()) do
if v:IsA("BasePart") then
local tween = TweenService:Create(v, tweenInfo, tweenGoal)
v.Touched:Connect(function()
v.CanTouch = false -- 'v' part will not trigger `Touched` events until re-enabled.
tween:Play()
tween.Completed:Wait() -- Wait for tween to complete.
v.CanCollide = false
end)
end
end