game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg == "/material" then
for _, child in plr.Character:GetDescendants() do
if child:IsA("BasePart") then
child.Material = Enum.Material.neon
end
end)
how do i make if player type /material it change all their body part material to neon
lmk if y know where i did go wrong
Youâre missing a few end lines for your for and if blocks, and the PlayerAdded connection. Do you have your output enabled in Studio? It should have told you that.
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg == "/material" then
for _, child in plr.Character:GetDescendants() do
if child:IsA("BasePart") then
child.Material = Enum.Material.Neon -- Neon should be capitalized.
end
end
end
end)
end)
Try this script (which used @Hypgnosis as a starter):
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
local msg = msg:split(" ")
if msg[1] == "/material" then
local material = string.gsub(msg[2], "^%l", function(newMsg) return string.upper(newMsg) end)
if Enum.Material[material] then
for _, child in plr.Character:GetDescendants() do
if child:IsA("BasePart") then
print(Enum.Material[material])
child.Material = Enum.Material[material]
end
end
end
end
end)
end)
NOTE: Two things to mention:
If the material you say after /material isnât a valid material according to Enum.Material, it will throw an error. But, it works if you say a valid material no matter what, so it shouldnât be an issue.
Not a problem with the script, but just to put it out there, there are quite a couple materials donât really have their effect work on the playerâs character.