How to make a limmited words game(I WAS SO BORED SO I DECIDED TO MAKE THIS LOL)

How to make a limited words game.

Hello!

I know the trend has already passed(Most likely), but I was bored and decided to make this.


NOTES

This is just the basics.
This will only show you how to make it so you have limited words. And when you run out, you are kicked.


With that being said . . .

LETS GET STARTED!


SETTING IT UP!

First things first, we need a script to do all this code right? So lets begin by setting up the player!
First we need to have the value of how many words they have left!

We are going to put the value into a folder, which will be leaderstats, that way we can see the words we have left!

Lets get started:

Put this into ServerScriptService. Call it whatever you want! Me personally, I’m going to call it
“Word Handler”

First lets set some variables, such as services and the default value.

local players = game:GetService('Players')
local defaultWords = 150

Next we have to put a folder into the player, then put the value in there. We do this all when the player joins!

local players = game:GetService('Players')
local defaultWords = 150

players.PlayerAdded:Connect(function(player)
	-- make the folder
	local leaderstats = Instance.new('Folder')
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = player
	
	-- make the value
	local value = Instance.new('NumberValue')
	value.Name = 'Words Left'
	value.Value = defaultWords -- set the default amount of words
	
	value.Parent = leaderstats
	
end)

THing


Next we need t make it so when they talk, it removes words depending on how many they say.
So first lets tell when they talk:

players.PlayerAdded:Connect(function(player)
	-- make the folder
	local leaderstats = Instance.new('Folder')
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = player
	
	-- make the value
	local value = Instance.new('NumberValue')
	value.Name = 'Words Left'
	value.Value = defaultWords -- set the default amount of words
	
	value.Parent = leaderstats
	
	player.Chatted:Connect(function(msg) -- MSG defines the Message. Which is what they said in the chat
		-- this runs when they chat! WOOP WOOP
	end)
end)

Now we have to:

  • Split up the message so we can get all the words
  • take away a word depending on the total amounts of words.
  • kick them if they run out of them.

So here we go!
First lets split up the message

	player.Chatted:Connect(function(msg) -- MSG defines the Message. Which is what they said in the chat
		local splitMessage = string.split(msg,' ') -- this will split the message everytime there is a space in what they say
	end)

I could make this so when they say other things like _ or - that counts as a new word but Im lazy.

Next lets explode!
JK

Next lets find out how many words to remove

	player.Chatted:Connect(function(msg) -- MSG defines the Message. Which is what they said in the chat
		local splitMessage = string.split(msg,' ') -- this will split the message everytime there is a space in what they say
		local words = #splitMessage -- the amount to remove
		
		
	end)

Next lets remove the words!
and then tell if it is equal to or less than 0. if so kick them

	player.Chatted:Connect(function(msg) -- MSG defines the Message. Which is what they said in the chat
		local splitMessage = string.split(msg,' ') -- this will split the message everytime there is a space in what they say
		local words = #splitMessage
		
		value.Value -= words
		if value.Value <= 0 then
			player:Kick('Ran out of letters!')
		end
	end)

And thats how you do it! Simple as that!
I tested this, it works!

4 Likes

Full code

local players = game:GetService('Players')
local defaultWords = 5

players.PlayerAdded:Connect(function(player)
	-- make the folder
	local leaderstats = Instance.new('Folder')
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = player
	
	-- make the value
	local value = Instance.new('NumberValue')
	value.Name = 'Words Left'
	value.Value = defaultWords -- set the default amount of words
	
	value.Parent = leaderstats
	
	player.Chatted:Connect(function(msg) -- MSG defines the Message. Which is what they said in the chat
		local splitMessage = string.split(msg,' ') -- this will split the message everytime there is a space in what they say
		local words = #splitMessage
		
		value.Value -= words
		if value.Value <= 0 then
			player:Kick('Ran out of letters!')
		end
	end)
end)```
1 Like

Just for educational purposes, could you please tell us how to make it so an underscore or dash counts as a word?

1 Like

Idk how. I was bored and just decided to make it.
Sorry!

Im to lazy to figure it out

Its completely fine! Ill try to find out myself.

1 Like

If you mean counting the text My name is John_Doe and I have a brother-in-law as 12 words instead of 9, then all you have to do is check the individual spaced-out words for the symbols you’re looking for.

local players = game:GetService('Players')
local defaultWords = 5

players.PlayerAdded:Connect(function(player)
	-- make the folder
	local leaderstats = Instance.new('Folder')
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = player
	
	-- make the value
	local value = Instance.new('NumberValue')
	value.Name = 'Words Left'
	value.Value = defaultWords -- set the default amount of words
	
	value.Parent = leaderstats
	
	player.Chatted:Connect(function(msg) -- MSG defines the Message. Which is what they said in the chat
		local words = 0
		for _, v in ipairs(splitMessage) do
			if v:find("-") and v:split("")[#v:split("")] ~= "-" then
				words += #v:split("-")
			elseif v:find("_") and v:split("")[#v:split("")] ~= "_" then
				words += #v:split("_")
			else
				words += 1
			end
		end
		value.Value -= words
		if value.Value <= 0 then
			print('Ran out of letters!')
		end
	end)
end)
1 Like

It’s not really reccommended though, some player could say something like “Hi- message” and they’d be confused as to why it’s not 2 words.

That can easily be fixed, I’ll update my post accounting for cases such as those.

Thanks!
I was to lazy(And had no idea how) To do this!

~Froyo~