Hello.
Little confused at changing transparency to 1 of a whole specific group of parts
like after player touches it triggered transparency to 1 after 5 seconds delay. any idea
Thanks in advance
This is actually a little bit more complex than you may think (if done correctly).
local players = game:GetService("Players")
local model = script.Parent --Place script inside the model.
local connections = {}
for _, child in ipairs(model:GetChildren()) do
if child:IsA("BasePart") then
local connection do
connection = child.Touched:Connect(function(hit)
local hitModel = hit:FindFirstAncestorOfClass("Model")
if hitModel then
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if hitPlayer then
for _, connection in ipairs(connections) do
connection:Disconnect()
end
task.delay(5, function()
for _, child in ipairs(model:GetChildren()) do
if child:IsA("BasePart") then
task.spawn(function()
child.Transparency = 1
end)
end
end
end)
end
end
end)
table.insert(connections, connection)
end
end
end
1 Like
I think you copied the code while I was making an edit, try now.
1 Like
Thanks Now its works fine. i feel its really different way to execute really thanks to you bro
local model = script.Parent
for i,v in pairs(model:GetDescendants()) do
v.Touched:Connect(function(BasePart)
if v:IsA("BasePart") and BasePart.Parent = "Humanoid" then
task.wait(5)
v.Transparency = 1
end
end
end)