Different text every log in

So I want to make it so everytime we log into the game a different text will be appeared in the “welcome back” textlabel…
i’m trash at scripting so yeah… unfortunately

By “different text”, do you mean that you want the textlabel to state something other than “welcome back” or for the font to change?

1 Like

you’ll need to use DataStores, save a dictionary of all text that needs to be displayed and check each time whether a bool value set to it is true, if displayed then simply display any other text and set it’s bool value to true in the saved dictionary.

edit:

or you could just save displayed text to a dataStore for every player

  -- existing array of  different text to be displayed
  local text = {"text1", "text2", "text3"}
  if not table.find(Store:GetAsync(key) , text[math.random(#text)]) then
         displayText() 
  end
  -- remember to use pcalls and all


exactly…

NameLabel.Text = plr.Name

If it’s a LocalScript then it’s game.Players.LocalPlayer.Name

I got the perfect solution for you my friend, just setup a table of all the possible things you want to say when the player joins the game, then use math.random to change the textlabel to one of the values in the table AKA whatever text you put in the table!

Heres an example!

local PossibleTexts = {
"Hey, welcome back!",
"How's it going!",
"Nice day isn't it!",
}

TextLabel.Text = PossibleTexts[math.random(1, #PossibleTexts)]
4 Likes

I meant that it’ll just display different texts every time, doesn’t matter which, just picks a number text from the script if i add it and then displays it.

@xurmx explained it perfectly.

A Datastore for this isn’t really ideal because it’s pulling a random value so, that would just make it more complicated.

1 Like

Thank you dude!!!

as the OP implied in the topic, they want different text every log in (I assumed each time a player logs in, not displaying text displayed before , hence different).

DataStores are then useless in this case (not taking text displayed earlier into consideration)

No problemo man, and if you want to get fancy with it you could even add tweening to it also!

As @xurmx mentioned, you can make a table and pick random phrases from it with a random number. However, I’d recommend using Random.new() instead of math.random() for better performance, but if you use a seed players won’t know a difference unless they look at the code:

local r = Random.new() 

local tbl = { 
	"Message 1, "; 
	"Message 2, "; 
	"Message 3, "; 
} 

local n = r:NextInteger(1,#tbl) 
label.Text = tbl[n] .. game.Players.LocalPlayer.Name .. "!" 

This is just an example and as you can see it’s closely related to the solution @xurmx gave, but it implements Random.new() instead of math.random which ROBLOX recommends as a better practice.

I don’t understand much of scripting lol, am just chillin with being trash :frowning: thank you anyways!

Well, not totally useless maybe the dev wants a specific message only said once for each player then I see where a datastore would come in handy!

1 Like

math.random() now uses a similar algorithm to Random, what do you mean?

2 Likes

Like he said, he’s a beginner at scripting so I think math.random is very simple to understand.

1 Like

From what I know, math.random() was the original method of pulling random numbers, but ROBLOX later introduced Random.new() which was supposed to be a more improved version since math.random() had some issues (especially without a seed). If they then went back and re-improved math.random() to work similarly, then I was unaware of this and it seems pointless for them to even introduce Random.new() as an alternative unless I’m misunderstanding something here.

Still, thanks for the info! I’ll probably still use Random.new() out of habit, but good to know all the math.random() scripts aren’t poor in performance as I thought.

I suppose, and there’s nothing wrong with your code, but I just believed Random.new() was more efficient (and I don’t see how it’s more complicated than math.random()), but if what @XxELECTROFUSIONxX says is true, then I was wrong and your method is just as good as mine. My apologies!

No your method is just as good man, keep it up :call_me_hand:

1 Like