Hi developers,
I’ve been trying to make a horror game for a long time and I thought of making a model or part appear and disappear. If anyone knows how I can make this script please give me a comment with it. Thank you!
set Part’s Transparency
It’s really simple. You just need to change the Part’s transparency on a loop:
local Part = workspace.Part --Put the part's location here
local WaitTime = 2 --Put the wait time you want in seconds
while wait(WaitTime) do
Part.Transparency = 1
wait(WaitTime)
Part.Transparency = 0
end
Open properties, and scroll to transparency, then change it from there. Same thing with reflectance etc.
There’s two ways I’d use to accomplish what you want to do here.
The first is by setting the part or model’s parent to ReplicatedStorage or somewhere else that isn’t Workspace or a descendant of it while in Studio. To make it appear and then disappear in-game, you set the parent of the part or model to Workspace, wait, and then set the parent back to whatever it was before.
local model = game:GetService("ReplicatedStorage").Model
local function appearDisappear(object)
local previousParent = object.Parent --Will use to set the parent to what it was parented to previously later
object.Parent = workspace --Set the parent to workspace, thus making it visible
wait(5)
object.Parent = previousParent --Set parent to the previous parent
end
appearDisappear(model)
The second would be setting the transparency like the reply above. If it’s a model, we loop through all the descendants and check if the descendant is a part.
local model = workspace.Model
local function appearDisappear(object)
if object:IsA("Model") then --If object is a model
for index, part in pairs(object:GetDescendants()) do --Loop through each descendant
if part:IsA("BasePart") then --Check to see if it's a BasePart (BasePart is a thing like a Part, MeshPart, Union, Wedge, etc.)
part.Transparency = 0 --Make it visible
end
end
wait(5) --wait
for index, part in pairs(object:GetDescendants()) do --Loop through each descendant again
if part:IsA("BasePart") then --If it's a BasePart
part.Transparency = 1 --Make it invisible
end
end
elseif object:IsA("BasePart") then --Else if object is a part
object.Transparency = 0 --Make visible
wait(5)
object.Transparency = 1 --Make invisible
end
end
appearDisappear(model)
I’ve written this so that you can use this with any object inside your scripts. I would personally use and recommend the first method as it’s quite simple and accounts for collision without having to do fancy shmancy stuff on your end. Feel free to ask any questions if you have any.
The below script will make your part disappear and appear:
local part = script.Parent --this is the script location(the script is the child of the part)
local time = 1 --this is the pause time
while true do --this will make the script repeat
part.Transparency = 1 --this will make the part invisible
wait(time) -- this will pause the code
part.Transparency = 0 --this will make the part visible
end --this will end your code
Hope I helped you!