Need Help Making A Fading Part

I’m new to script and right now I’m trying to figure out how to make a fading part. I just can’t seem to figure it out though.

-Here’s The Script

local fadingPart = game.Workspace.FadingPart
local fading = false

local function OnTouch(Touched)
local char = Touched.Parent
local humanoid = char:FindFirstChildWhichIsA(“Humanoid”)
if humanoid then
fading = true
while fading == true do
fadingPart.Transparency = fadingPart.Transparency(1, 0)
task.wait(0.01)
end
task.wait(1)
fading = false
end
end

Try this, it makes any values change smoothly:
https://create.roblox.com/docs/reference/engine/classes/TweenService

  1. The Transparency property should be set to a value, not treated as a function.
  2. The loop that sets the transparency continuously may cause performance issues. You can use a Tween to achieve a smoother fade.

Not sure if itll work but something like

local fadingPart = game.Workspace.FadingPart
local fading = false

local function OnTouch(hit)
    local character = hit.Parent
    local humanoid = character:FindFirstChildOfClass("Humanoid")

    if humanoid and not fading then
        fading = true
        local tweenInfo = TweenInfo.new(1)  -- Set the time for the fade (in seconds)
        local goal = {}
        goal.Transparency = 1  -- Fully transparent

        local tween = game:GetService("TweenService"):Create(fadingPart, tweenInfo, goal)
        tween:Play()

        tween.Completed:Connect(function()
            task.wait(1)  -- Wait for 1 second after fading
            fadingPart.Transparency = 0  -- Reset transparency to fully opaque
            fading = false
        end)
    end
end

fadingPart.Touched:Connect(OnTouch)

I looked at the page and i think i figured it out, thanks!

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