Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a part disappear and appear again smoothly?

Asked by 2 years ago

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!

1 answer

Log in to vote
0
Answered by
ryanzhzh 128
2 years ago
Edited by appxritixn 2 years ago

"the world's easiest question" but on to the question:

Using tweens to do this is cooler than this:

for i = 0, 1, 0.001 do
    script.Parent.Transparency = i
end

To use it, let's set up a TweenInfo for the tween settings.


local info = TweenInfo.new( Time = 5, -- Amount of time that it takes to finish the tween. EasingStyle = Enum.EasingStyle.Quad, -- The easing style, info can be found here: https://developer.roblox.com/en-us/api-reference/enum/EasingStyle EasingDirection = Enum.EasingDirection.Out, -- The easing direction, info can be found here: https://developer.roblox.com/en-us/api-reference/enum/EasingDirection repeatCount = 0, -- How many times to repeat, optional. reverses = false, -- Does it tween undo after tween, optional. delayTime = 0 -- Time to wait before tweening. )

Now we'll set up a property table to change. It adds for certain property types like Vector3.


local propertyTable = { Transparency = 1 }

Time to tween!


local myPart -- The part to affect local myTween = game:GetService("TweenService"):Create(myPart, propertyTable, info)

Now we can do alot of things, but we will only :Play it. To know more, look at this: https://developer.roblox.com/en-us/api-reference/class/Tween.

Full code:


local info = TweenInfo.new( 5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0 ) local propertyTable = { Transparency = 1 } local myPart -- The part to affect local myTween = game:GetService("TweenService"):Create(myPart, propertyTable, info) myTween:Play()

That's it!

Links:

https://developer.roblox.com/en-us/api-reference/enum/EasingStyle https://developer.roblox.com/en-us/api-reference/enum/EasingDirection https://developer.roblox.com/en-us/api-reference/class/Tween https://developer.roblox.com/en-us/api-reference/function/TweenService/Create

0
Hyperlinked the links in the answer. appxritixn 2235 — 2y
0
I tried to link them, but when I linked them, it linked to another page. ryanzhzh 128 — 2y
Ad

Answer this question