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

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

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

✓ Accepted answer

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!

2 comments

0

Sorry about the formatting i cant fix it

0

It works only once when I try to click the button but still thank you

Check this

Button.ClickDetector.MouseClick:Connect(function()
	
	local Materials = Enum.Material:GetEnumItems() 
	local RandomMaterial = Materials[math.random(#Materials)] 

	script.Parent.Material = RandomMaterial
	
end)

1 comment

0

You dont have a click detector on a button you can just do .Activated:Connect or :MouseButton1Down:Connect

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