Destroy head When say Destroy inchat

I Want to make a Script where if the player says Destroy in the chat The player’s Head Gets deleted and he dies.

I Wrote a script but it does not seem to work. No errors or anything. It just does not work. Here is the Script:

local PlayersService = game:GetService (“Players”)
local StringToDetect = “Destroy”
local Destroy2 = Player.Character:FindFirstChild(“Head”)

PlayersService.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.find(string.lower(Message), string.lower(StringToDetect)) then
if Player.Character then
Player.Character:FindFirstChild(“Head”)
Destroy2:Destroy()
end
end
end)
end)

1 Like

You would need to define what Destroy2 is after the player had chatted, that way it can detect what the player is, and where it got the character from.

I Made a few changes Here is the script:

local PlayersService = game:GetService (“Players”)
local StringToDetect = “Destroy”

PlayersService.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.find(string.lower(Message), string.lower(StringToDetect)) then
if Player.Character then
game:GetService (“Players”).Players.Character:FindFirstChild(“Head”)
end
end
end)
end)

But now it shows an error:

Players is not a valid member of Players “Players”

This should work.

local PlayersService = game:GetService("Players")
local StringToDetect = "Destroy"

PlayersService.PlayerAdded:Connect(function(Player)
  Player.Chatted:Connect(function(Message)
    if string.find(string.lower(Message), string.lower(StringToDetect)) then
      if Player.Character then
        Player.Character:FindFirstChild("Head")
      end
    end
  end)
end)
3 Likes