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

What's wrong with my disappearing platform script?

Asked by
hvnte_r 10
3 years ago
Edited 3 years ago

I'm attempting to code a disappearing platform with multiple parts. Once the player steps on the platform, the entire thing should gradually disappear and reappear shortly after. The script is also meant to apply to every model in workspace by the name of "Platform". (no quotes)

Once a platform is stepped on, no errors are shown yet nothing happens.

Here is my script:

num = 40

local platform = Instance.new("Platform",game.Workspace)

for _, instance pairs(workspace:GetChildren()) do
    if instance.Name == 'Platform' then
        for _, instance_2 in pairs(instance:GetDescendants()) do
            function onTouched(hit)
                for i = 1, num do
                instance.Transparency = 0.5+1/num/2 
                    instance.CanCollide = false
                    wait()
                end

                for i = 1, num do
                instance.Transparency = 1 - i/num/2
                    instance.CanCollide = true
                    wait()
            end

            instance.Touched:connect(onTouched)
        end
    end
end

Also I have extremely little knowledge of Lua, so you may have to explain this to me in caveman terms.

1 answer

Log in to vote
0
Answered by 3 years ago

This here should fix your errors, let me know if you're still having any errors.

local model = game.Workspace.DissapearingBricks -- change this to the model/folder that holds your dissapearing bricks
local num = 40

for _, brick in pairs(model:GetChildren()) do -- looping through every part in the model specified
    brick.Touched:Connect(function(hit) -- calling the touch event for every brick/part in the model
        if hit.Parent:FindFirstChild("Humanoid") then -- checking if a player touched the brick
            for i = 1, num do
                brick.Transparency = 0.5+1/num/2 
                brick.CanCollide = false
                wait()
            end

            for i = 1, num do
                brick.Transparency = 1 - i/num/2
                brick.CanCollide = true
                wait()
            end
        end
    end)
end
0
No, for some reason nothing still happens. Is it because I have the script in workspace? hvnte_r 10 — 3y
0
Nevermind! I figured it out. The platform models are inside of a folder, that's why the script wasn't running. Thank you for your help! hvnte_r 10 — 3y
0
No problem! incurszio 70 — 3y
Ad

Answer this question