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

GetChildren [CanCollide/Transparency Onclick?]

I'm trying to make the Children of these bricks CanCollide True/False And transparency change OnClick. Here's my Script.

local isOn = true

function on() isOn = true script.Parent.Pos1.GetChildren().CanCollide = true script.Parent.Pos1.GetChildren().Transparency = 0 script.Parent.Pos2.GetChildren().CanCollide = false script.Parent.Pos2.GetChildren().Transparency = 1 end

function off() isOn = false script.Parent.Pos1.GetChildren().CanCollide = false script.Parent.Pos1.GetChildren().Transparency = 1 script.Parent.Pos2.GetChildren().CanCollide = true script.Parent.Pos2.GetChildren().Transparency = 0 end

function onClicked()

if isOn == true then off() else on() end

end

script.Parent.Pos1.GetChildren().ClickDetector.MouseClick:connect(onClicked) script.Parent.Pos2.GetChildren().ClickDetector.MouseClick:connect(onClicked)

on()

1 answer

✓ Accepted answer

This should work:

local isOn = true

function on() isOn = true script.Parent.Pos1.GetChildren().CanCollide = true script.Parent.Pos1.GetChildren().Transparency = 0 script.Parent.Pos2.GetChildren().CanCollide = false script.Parent.Pos2.GetChildren().Transparency = 1 end

function off() isOn = false script.Parent.Pos1.GetChildren().CanCollide = false script.Parent.Pos1.GetChildren().Transparency = 1 script.Parent.Pos2.GetChildren().CanCollide = true script.Parent.Pos2.GetChildren().Transparency = 0 end

function onClicked()

if isOn == true then off() else on() end
end

script.Parent.Pos1.MouseButton1Down:connect() --I think you were doing this part wrong 
script.Parent.Pos2.MouseButton1Down:connect() 

on()

1 comment

0

Thanks.

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