hello and good morning developers, I have a bug present in this code and I would like you to help me to solve it.
game.players.playeradded:connect(function(player)
player.chatted:connect(function(msg)
if msg:lower() == ("andres tate") then
local descendants = player.characteradded.wait():getdescendants()
for _, v in pairs(descendants) do
if v:findfirtschild("handle") then
if v.handle:findfirschild("HairAttachment") or v.handle:findfirschild("HatAttachment") then
end
end
end
end
end)
end)
what I want to do is that when I say “andres tate” in the roblox chat, the accessories disappear from my head.
This may have to do with capitalisation or typos in your Script. I’ve fixed them for you, so try it out and see if it works:
game.Players.PlayerAdded:connect(function(player)
player.Chatted:Connect(function(msg)
if msg:lower() == ("andres tate") then
local descendants = player.CharacterAdded.Wait():GetDescendants()
for _, v in pairs(descendants) do
if v:FindFirstChild("Handle") then
if v.Handle:FindFirstChild("HairAttachment") or v.Handle:Findfirschild("HatAttachment") then
-- Your code here to destroy the Player’s accessories.
end
end
end
end
end)
end)
If this script doesn’t work/work as intended, it might mean that:
- You are running this on a LocalScript.
- You are using the new
TextChatService
instead of the classic Chat
, which .Chatted
will only work in the classic one.
game:GetService("Players").PlayerAdded:connect(function(player)
player.Chatted:Connect(function(message)
if string.lower(message) == "andres tate" then
for _, object in player.Character:GetDescendants() do
local handle = object:FindFirstChild("Handle")
if handle then
local hair = handle:FindFirstChild("HairAttachment")
if hair then hair:Destroy() end
local hat = handle:FindFirstChild("HatAttachment")
if hat then hat:Destroy() end
end
end
end
end)
end)