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

Help with material onClicked?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

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)
0
You forgot Screen:GetChildren()? TheDeadlyPanther 2460 — 8y
0
is there a click detector in the brick? duckyo01 120 — 8y
0
Yes, there is ducky. TheDeadlyPanther 2460 — 8y
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? TheDeadlyPanther 2460 — 8y
View all comments (3 more)
0
I know how to get the parents, it's just the material is not chnaging.. FiredDusk 1466 — 8y
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. TheDeadlyPanther 2460 — 8y
0
I can't answer this, I have tested multiple times in studio, and there is no new way of indexing materials. Sorry TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
8 years ago

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

Ad

Answer this question