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

how do you change part's material to random material when you click text button?

Asked by
Kneaks 4
4 years ago

Hi I'm not good at scripting and I want to know how to change a part's material to a random material when u click a text button I saw something like it before but it only did it once and didn't work again please help

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Scripting helpers is not a requesting site so in the future make a script and if you cant find out the error, post it here. But i will help you out anyway. You could make the gui call a remote event. When it is called, you can then use a math.random and use a ling if statement like this (There is probably a better way to do this but this is what i thought of)

local number = math.random(1,3)
if number == 1 then
    part.texture = "concrete"
elseif number == 2 then
    part.texture = "neon"
elseif number == 3 then
    part.texture = "brick"
end

This would obviously be longer to fit however many textures you would like to add. To increse the length you would just change the 3 to how many textures you want ~~~~~~~~~~~~~~~~~ math.random(1,3) <--- this 3

and adding another one of these onto the end but changing the number to go up in 1 each time and the texture to a different texture

elseif number == 3 then part.texture = "brick" end ~~~~~~~~~~~~~~~~~ I hope this helps!

0
Sorry about the formatting i cant fix it adieking1 69 — 4y
0
It works only once when I try to click the button but still thank you Kneaks 4 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Check this

Button.ClickDetector.MouseClick:Connect(function()

    local Materials = Enum.Material:GetEnumItems() 
    local RandomMaterial = Materials[math.random(#Materials)] 

    script.Parent.Material = RandomMaterial

end)
0
You dont have a click detector on a button you can just do .Activated:Connect or :MouseButton1Down:Connect adieking1 69 — 4y

Answer this question