Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's wrong with my disappearing platform script?

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

✓ Accepted answer

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

3 comments

0

No, for some reason nothing still happens. Is it because I have the script in workspace?

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!

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.