How would I script this?

I want to create a game based off those TikTok story times. I want to make it so when a player joins they will see a gui that will randomizes a number and that number is displayed above their character, and when they run out of words they get kicked from the game. I also want to implement a system where users can give words to others

You can use math.random(low,max) for picking the random number.

For kicking the player when they have no more words left, make a player chatted function inside of a player added function and wait for them to say something. When they say something, check their current amount of words, for example by checking the text on the textlabel on top of their head. If its ~= (not equal to) to 0 then deduct 1 word from their words and update the textlabel, else you can use datastores to update their words to 0.

When a player joins, check how many words are on the datastore, if its equal to 0, kick them. If its above 0, dont do anything and let them join.

Also, just to add on;
Its best to add a while wait() function to check players words every 5-10 seconds, achieveable with a for loop through the players, If their words are equal to 0 then update the datastore to 0 and kick them. Otherwise, do nothing.

Basically you want a game like Limited Words!, everything you just said perfectly fits the description of the game exactly.

A game EXACTLY like this already exists. (Sorry if I’m late to mention this, but it’s not recommended to play popular Roblox games right now, as you could get your account deleted) Everything you described, it’s all there. If you’re trying to make money from this game, I’d probably come up with a different concept if I were you.

But, if you’re just making this for fun, here’s how:

Create a LocalScript in StarterPlayer.StarterPlayerScripts, giving the player a random amount of words, and then checking when they chat, checking how many spaces are in the message, and deducting the same amount of words as there are spaces in the message.

game.Players.PlayerAdded:Connect(function(player)
	local Words = math.random(1, 1000) --Change these to your liking
	player.Chatted:Connect(function(msg)
		local spaces = 0
		for i = 1, #msg do
			if string.sub(msg, i, i) == " " then
				spaces += 1
			end
		end
		spaces += 1 --This is because there is no space at the end of each message.
		Words -= spaces
	end)
end)

And, for showing how many words they have, create a BillboardGui positioned directly above the player’s head, but relative to the HumanoidRootPart.

I’m in a bit of a rush, so I can’t really explain much more, but good luck!

1 Like