Need help with coding a one word at a time game

Hey there! I’m trying to make a game, that kicks you if you use more than one word. Its like “limited words” and whatnot, but you can ONLY say one word at a time. More than one word in your message will kick you, but if you want me to, perhaps I could allow spaces as well, like: “pizza [space]”, but its up to you.

I have had some code (credit to Buzzettego, the creator of the code), but when I say more than one word, it doesn’t kick me…

local SendWordsRE = game.ReplicatedStorage.SendWords

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local head = character:WaitForChild("Head")
		
		local WordsAmountGui = script.WordsAmount:Clone()
		local WordsGui = script.WordsGui:Clone()
		
		local oneWordIntValue = Instance.new("IntValue", player)
		oneWordIntValue.Name = "WordsAmount"
		oneWordIntValue.Value = 1
		
		player.Chatted:Connect(function(message)
			local amount = #string.split(message)
			if amount >= oneWordIntValue.Value then
				player:Kick("You said more than one word!")
			end
		end)
	end)
end)

Any ideas? Yes I am a noob at coding, and yes I am giving credit to this person (for making the script) and of course, whoever helps me. Heck, I might credit everyone who is helpful to me, but your choice :person_shrugging:

String.split takes two arguments

  1. the string
  2. the character to split the string by
    If you want to find out if the player is saying a sentence you can seperate by spacebar characters " "
1 Like

Right here I believe is where the issue lies, you run string.split() and provide the message but you never say what it should split, I believe putting a ," " after the message variable in the string.split should fix it.

1 Like
local message = "Hello World"
local split = string.split(message, " ") -- {"Hello", "World"}
if #split > 1 then
   --kick player
end
2 Likes
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local head = character:WaitForChild("Head")
		
		player.Chatted:Connect(function(message)
			local amount = #string.split(message," ")
			if amount > 1 then
				player:Kick("You said more than one word!")
			end
		end)
	end)
end)

I got this code so far, but nothing seems to be working…

Nevermind, it works. Its just the
local amount = #string.split(message," ")
that needs a space between the , and "

Like:
local amount = #string.split(message, " ")

if this was solved mark it as solved.

if string.find(message, "%s") then
More efficient to just search for a whitespace character and act accordingly.

2 Likes