How to make a part disappear smoothly

Hello,
I’m working on a spleef game and the script that makes the parts disappear and appear some seconds after is this:

local Part = script.Parent
local debounce = true 

Part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid and debounce == true then
        debounce = false 
        Part.Transparency = 0.5
        wait(1)
        Part.Transparency = 1
        Part.CanCollide = false
        wait(8)
        Part.Transparency = 0
        Part.CanCollide = true
        debounce = true
    end 
end)

how can I make the part disappear and appear again smoothly?

Thanks in advance!

You can use TweenService. Pass the part Transparency as the property you wish to smoothly change.

I believe there are many posts on this on the forum.

TweenService with Transparency Example

1 Like

The post you’ve linked talks about GUI. Is it the same thing if I use the same example on the part?

Yes, you can tween a parts transparency the exact same as a gui.

1 Like

Here is the link to the wiki: TweenService | Roblox Creator Documentation
It will explain everything about the TweenService

1 Like

First off, wait() is deprecated, please use task.wait() next time
This is what I would do to make smooth disappearing and reappearing
TweenService is not only for GUI’s by the way

local TweenService =  game:GetService("TweenService")
local Part = script.Parent
local debounce = true

-- Enum.EasingStyle and Enum.EasingDirection are optional
local DisappearTweeningInfo = TweenInfo.new(--[[how long it takes to disappear]])
local AppearTweeningInfo = TweenInfo.new(--[[how long it takes to reappear]])

-- Using Goals allows you to edit more than 1 property of an object at a time!
--[[ Quick Example of Goals
   local Goal = {}
   Goal.Transparency = 0
   Goal.Position = Vector3.new(10, 10, 10) 
]]

local DisappearGoal = {}
DisappearGoal.Transparency = 1

local AppearGoal = {}
AppearGoal.Transparency = 0

Part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid and debounce == true then
        debounce = false
        TweenService:Create(Part, DisappearTweeningInfo, DisappearGoal):Play()
        Part.CanCollide = false
        task.wait(8)
        TweenService:Create(Part, AppearTweeningInfo, AppearGoal):Play()
        Part.CanCollide = true
        debounce = true
    end
end)

This should work, give it a try


Returns this error in the console

oh shoot, i forgot to add hit as a parameter in Part.Touched, lol, my mistake

try grabbing the code now and see if it works

This is my code:

local TweenService =  game:GetService("TweenService")
local Part = script.Parent
local debounce = true

-- Enum.EasingStyle and Enum.EasingDirection are optional
local DisapearTweeningInfo = TweenInfo.new(0.2)
local AppearTweeningInfo = TweenInfo.new(8)

-- Using Goals allows you to edit more than 1 property of an object at a time!
--[[ Quick Example of Goals
   local Goal = {}
   Goal.Transparency = 0
   Goal.Position = Vector3.new(10, 10, 10) 
]]

local DisappearGoal = {}
DisappearGoal.Transparency = 1

local AppearGoal = {}
AppearGoal.Transparency = 0

Part.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid and debounce == true then
		debounce = false
		TweenService:Create(Part, DisappearTweeningInfo, DisappearGoal):Play()
		Part.CanCollide = false
		task.wait(8)
		TweenService:Create(Part, AppearTweeningInfo, AppearGoal):Play()
		Part.CanCollide = true
		debounce = true
	end
end)
DisappearTweeningInfo

seems to be underlined in red, and the smooth disappear/appear doesn’t work

1 Like

The spelling in disappear differs from disapear in the script, check for typos.

2 Likes

i misspelled disappear lol lemme send u the code again

1 Like

This should work, check for typos (just in case lol)

local TweenService =  game:GetService("TweenService")
local Part = script.Parent
local debounce = true

-- Enum.EasingStyle and Enum.EasingDirection are optional
local DisappearTweeningInfo = TweenInfo.new(--[[how long it takes to disappear]])
local AppearTweeningInfo = TweenInfo.new(--[[how long it takes to reappear]])

-- Using Goals allows you to edit more than 1 property of an object at a time!
--[[ Quick Example of Goals
   local Goal = {}
   Goal.Transparency = 0
   Goal.Position = Vector3.new(10, 10, 10) 
]]

local DisappearGoal = {}
DisappearGoal.Transparency = 1

local AppearGoal = {}
AppearGoal.Transparency = 0

Part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid and debounce == true then
        debounce = false
        TweenService:Create(Part, DisappearTweeningInfo, DisappearGoal):Play()
        Part.CanCollide = false
        task.wait(8)
        TweenService:Create(Part, AppearTweeningInfo, AppearGoal):Play()
        Part.CanCollide = true
        debounce = true
    end
end)
1 Like

Seems to work now! You are a king! Thank you so much

1 Like

No problem! Glad i was able to help!

2 Likes

i tried this but for some reason it only effects the transparency of the part but not the collision status :confused:

Maybe you didnt set the cancollide to false? Also, this has to be in a serverscript so collisions are disabled properly for all players.