Scripting 在ROBLOX工作室,当物体碰到某些砖块时,如何使其消失?

Scripting 在ROBLOX工作室,当物体碰到某些砖块时,如何使其消失?,scripting,roblox,Scripting,Roblox,我试着制作一个有掉落的砖块水平的obby,砖块掉落很好,但我希望它们在碰到某个砖块时消失,这样它们就不会看起来很凌乱。有什么帮助吗?假设每个掉落的部分都是一个新的部分,当角色接触到该部分时,您可以简单地将其销毁 script.Parent.Touched:connect(function(hit) if hit:FindFirstChild('Humanoid') then -- Check if it is a character that touched the part

我试着制作一个有掉落的砖块水平的obby,砖块掉落很好,但我希望它们在碰到某个砖块时消失,这样它们就不会看起来很凌乱。有什么帮助吗?

假设每个掉落的部分都是一个新的部分,当角色接触到该部分时,您可以简单地将其销毁

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

被接受的答案不再有效,这对我来说是有效的:

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
)

我想我知道出了什么问题。这是我的密码

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)
制作一个部件并将其命名为block,然后插入一个带有上述代码的脚本,它将完美地工作。 (您可以通过多次复制和粘贴“等待(1)”和“块透明度”并减小数字,使其更平滑。例如:

        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
请注意,我是如何将CanCollide值设置为true直到某一点的。这一点很重要,因为:你一触到它,该块就会消失,不会给玩家一个跳跃的机会。相反,它消失得足够晚,让玩家有时间作出反应。

FindFirstChild(“类人”)不起作用-事件永远不会触发