Reputation: 95
I'm trying to make an obby with a falling blocks level and the bricks fall fine but I want them to disappear when they touch a certain block so they don't look messy. Any help?
Upvotes: 1
Views: 8068
Reputation:
I think i know what went wrong. Here is my code.
local block = script.Parent
local debounce = true
block.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if humanoid and debounce == true then
debounce = false
block.Transparency = 0.5
wait(1)
block.Transparency = 1
block.CanCollide = false
wait(3)
block.Transparency = 0
block.CanCollide = true
debounce = true
end
end)
Make a part and name it block, and then insert a script with the code above and it will work perfectly. (You can make it more smooth by copying and pasting "wait(1)" and "block transparency" multiple times and making the numbers smaller. Example:
local block = script.Parent
local debounce = true
block.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if humanoid and debounce == true then
debounce = false
block.Transparency = 0.1
wait(0.2)
block.Transparency = 0.2
block.CanCollide = true
wait(0.2)
block.Transparency = 0.3
block.CanCollide = true
wait(0.2)
block.Transparency = 0.4
block.CanCollide = true
wait(0.2)
block.Transparency = 0.5
block.CanCollide = true
wait(0.2)
block.Transparency = 0.6
block.CanCollide = true
wait(0.2)
block.Transparency = 0.7
block.CanCollide = false
wait(0.2)
block.Transparency = 0.8
block.CanCollide = false
wait(0.2)
block.Transparency = 0.9
block.CanCollide = false
wait(0.2)
block.Transparency = 1
block.CanCollide = false
wait(3)
block.Transparency = 0
block.CanCollide = true
debounce = true
Notice how i set the CanCollide value to true up until a certain point. This is important because: The block would disappear as soon as you touched it, not giving the player a chance to jump. Instead, it disappears late enough to give the player time to react.
Upvotes: 0
Reputation: 1
The accepted Answer does not work anymore, this is what worked for me:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA('Humanoid') then -- Check if it is a character that touched the part
script.Parent:Destroy()
end
end
)
Upvotes: 0
Reputation: 241
Assuming that each falling part is a new part, you can simply destroy the part when it is touched by a character.
script.Parent.Touched:connect(function(hit)
if hit:FindFirstChild('Humanoid') then -- Check if it is a character that touched the part
script.Parent:Destroy()
end
end
Upvotes: 2