ASTROCPF
(Astronaught)
November 4, 2022, 9:16pm
#1
(Sorry, I don’t know if this code is a table or not)
local texts = {
"text1",
"text2",
"text3"
}
text.text = (texts[math.random(1, #texts)])
--script.parent.text is the text.text
How do I change (texts[math.random(1, #texts)])
into the text?
I want one of the 3 texts to be put as the text.
GuySalami
(GuySalami)
November 4, 2022, 9:21pm
#2
texts[math.random(1, #texts)]
should return a string, like
texts[2]
returns "text2"
.
ASTROCPF
(Astronaught)
November 4, 2022, 9:23pm
#3
Isn’t that was I exactly did?
Summary
This text will be hidden
GuySalami
(GuySalami)
November 4, 2022, 9:23pm
#4
Yes, so I don’t see the problem, is there an error message?
ASTROCPF
(Astronaught)
November 4, 2022, 9:24pm
#5
No, I dont know why this isn’t working. Want to see the whole script?
GuySalami
(GuySalami)
November 4, 2022, 9:25pm
#6
I guess it doesn’t hurt to see the script.
Also, is the text and textLabel visible?
ASTROCPF
(Astronaught)
November 4, 2022, 9:28pm
#7
local text = script.Parent
game.Players.PlayerAdded:Connect(function()
local texts = {
"text1",
"text2",
"text3"
}
text.text = (texts[math.random(1, #texts)])
end)
Yes.
If you want the workspace I can give you that, and a screenshot of what the text is in the game.
GuySalami
(GuySalami)
November 4, 2022, 9:34pm
#8
I assume this is a server script, not in the StarterGUI (Because you don’t use PlayerAdded
in StarterGUI, nor do you typically do so in a LocalScript), so maybe make sure the script and TextLabel is under starterGUI, or get’s parented to the player’s gui.
Also, if you must use game.Players
, try using local Players = game:GetService("Players")
.
ASTROCPF
(Astronaught)
November 4, 2022, 9:36pm
#9
Oops, my bad. I used player added in starterGUI. I removed PlayerAdded and stuff but it still doesn’t work.
GuySalami
(GuySalami)
November 4, 2022, 9:38pm
#10
try using a print statement like this:
local texts = {
"text1",
"text2",
"text3"
}
local textLabel = script.Parent
local text = texts[math.random(1, #texts)]
print(text)
textLabel.Text = text
1 Like
ASTROCPF
(Astronaught)
November 4, 2022, 9:44pm
#11
I tried that, it still didn’t work.
GuySalami
(GuySalami)
November 4, 2022, 9:44pm
#12
What did it print in the console?
ASTROCPF
(Astronaught)
November 4, 2022, 9:48pm
#13
it printed one of the texts, but it also printed “Text is not a valid member of Text label”
Edit: you probably forgot to capitalize .text into .Text
Edit 2: it works now, you just forgot to capitalize
GuySalami
(GuySalami)
November 4, 2022, 9:50pm
#14
OH, the property is Text
, not text
, I should have realized that earlier lol.
1 Like
ASTROCPF
(Astronaught)
November 4, 2022, 9:53pm
#15
Thanks for helping! now I can refer to this whenever I have the same problem.
1 Like
system
(system)
Closed
November 18, 2022, 9:53pm
#16
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.