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

Why won't my onclick function attic staircase work?

function onClicked()
script.Parent.Parent.Parent.StairCase.Transparency = 0
script.Parent.Parent.Parent.StairCase.CanCollide = true
script.Parent.Parent.Parent.TrapClose.Transparency = 1
script.Parent.Parent.Parent.TrapClose.CanCollide = false
script.Parent.Parent.Parent.TrapOpen.CanCollide = true
script.Parent.Parent.Parent.TrapOpen.Transparency = 0

wait (10)

script.Parent.Parent.Parent.StairCase.Transparency = 1
script.Parent.Parent.Parent.StairCase.CanCollide = false
script.Parent.Parent.Parent.TrapClose.Transparency = 0
script.Parent.Parent.Parent.TrapClose.CanCollide = true
script.Parent.Parent.Parent.TrapOpen.CanCollide = false
script.Parent.Parent.Parent.TrapOpen.Transparency = 1

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

http://prnt.sc/dfe6eo

1 answer

You can't set the transparency and cancollide of a model, the model is just grouping the parts together. You'd have to get the children individually and change the transparency and cancollide like so:

function changechildren(parent, transparency, cancollide)
	for i,v in pairs(parent:GetChildren()) do
		v.Transaprency = transparency
		v.CanCollide = cancollide
	end
end


function onClicked()
changechildren(script.Parent.Parent.Parent.StairCase, 0, true)
changechildren(script.Parent.Parent.Parent.TrapClose, 1, false)
changechildren(script.Parent.Parent.Parent.TrapOpen, 0, true)
 
wait (10)
 
changechildren(script.Parent.Parent.Parent.StairCase, 1, true)
changechildren(script.Parent.Parent.Parent.TrapClose, 0, false)
changechildren(script.Parent.Parent.Parent.TrapOpen, 1, true)
 
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

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