I have a local script that's in a tool, and when you click it, it's supposed to make your character change into one of the materials from an array, but it only works once and won't change anything afterwards. I've been changing things for half an hour and haven't come up with any ideas as to what's wrong with it.
char = game.Players.LocalPlayer.Character:GetChildren() tool = script.Parent materials = {"Grass","Wood","Neon"} m = materials[math.random(#materials)] tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() for i,v in pairs(char) do if v:IsA("Part") then v.Material = m end end end) end)
player = game.Players.LocalPlayer repeat wait() until player.Character --Gotta wait for the character before you can use it. char = player.Character:GetChildren() tool = script.Parent materials = {"Grass","Wood","Neon"} tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() local m = materials[math.random(#materials)] --I put line 4 down here so it will be a random material every time the mouse is clicked. for i,v in pairs(char) do if v:IsA("Part") then v.Material = m end end end) end)