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

Help with material onClicked?

NOTE: I KNOW HOW TO GET THE PARENTS, ALL PARENTS ARE RIGHT AND THE MATERIAL OF SCREEN IS FOIL!! HELP PLEASE!

--//Variables
Button = script.Parent
Screen = script.Parent.Parent.Screen

--//Function
Button.ClickDetector.MouseClick:connect(function()

	for i,v in pairs {Screen} do
		if v.Material == "Foil" then
			print"Worked2"
			v.Material = "Neon"
			
		end
	end
end)

7 comments

0

You forgot Screen:GetChildren()?

0

is there a click detector in the brick?

0

Yes, there is ducky.

0

When I tried it how you made it, I got an error: Material is not a valid member of model (I was using a model to store the children). Is this meant to have a :GetChildren() table? Or are you just trying to find the object called 'screen' in Workspace?

0

I know how to get the parents, it's just the material is not chnaging..

0

Are you doing a table, though? or is it just one part, cause if it's one part, then you don't need a for loop.

0

I can't answer this, I have tested multiple times in studio, and there is no new way of indexing materials. Sorry

1 answer

error is on line 9.

you need use Enum to tell the script what material you are talking about.

so,instead of using: if Material == "Foil"

you should use:Material == Enum.Material.Foil

so i went ahead and re-made your script.

i tested this new script hope it works for you too

--//Variables
Button = script.Parent
Screen = script.Parent.Parent.Screen:GetChildren()

--//Function
Button.ClickDetector.MouseClick:connect(function()

    for i=1, #Screen do
        if Screen[i].Material == Enum.Material.Foil then
            print"Worked2"
            Screen[i].Material = Enum.Material.Neon

        end
    end
end)

hope this works

lukeb50

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