Why it isn't working?

I’m new with chat commands but i wanted to do it to simplify my tests.
I did this script but is not working properly.

local function onPlayerChatted(player, message)
	if message == 'removehead' and player.Character and player.Character:FindFirstChild("Head") then
		player.Character.Head:Destroy()
	end
	if message == "\give SwordKit" then
		print("message recived")
		local path = game.ServerStorage.Katana.SwordKit
		for i,v in ipairs(path:GetChildren())do
			print('done for the ',i,' time')
			local obj = v:Clone()
			obj.Parent = player.Backpack
		end
	end
end


local function onPlayerAdded(player)
	player.Chatted:Connect(function (message) onPlayerChatted(player, message) end)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)

I find it strange that if i say removehead it works but if i say \give SwordKit it doesn’t.
No error messages.

What did I do wrong?

It’s because of the \ special character at the start of the string which makes the next character treated like an actuall character no matter what which is useful for some special cases when used alone. It turns into “give SwordKit” from “\give SwordKit”. Changing it to “\\give SwordKit” will treat the 2nd \ character in the string as an actual character.

So how can I make it so when i type in chat \give something to react?(to count " \ " as a character)

I already said it in my message, add 2 of them together.

1 Like

i didn’t see the edit, my bad

it works, thanks
(30 ch@aracters
)