Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does this script not affect the text in my text label?

Asked by 6 years ago
local Parent = script.Parent

Letters1 = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
Numbers1 = {"1","2","3","4","5","6","7","8","9","0"}
Letters2 = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
Numbers2 = {"1","2","3","4","5","6","7","8","9","0"}
Numbers3 = {"1","2","3","4","5","6","7","8","9","0"}

game.Players.PlayerAdded:connect(function(Player)
    local Figure1 = Letters1[math.random(#Letters1)];
    local Figure2 = Letters1[math.random(#Numbers1)];
    local Figure3 = Letters1[math.random(#Letters2)];
    local Figure4 = Letters1[math.random(#Numbers2)];
    local Figure5 = Letters1[math.random(#Numbers3)];
        wait(15)   
        Parent.Text = "Current Subject "+Figure1+Figure2+"-"+Figure3+Figure4+Figure5
        print("Working")
end)

Script logic : when player joins, script generates a random 2 fig - 3 fig order. Why isn't it working?

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

In Lua, the concatenation operation is .. and not +. Also, this script could be a lot more efficient.

Also, to get a random value from an array, it is array[math.random(1,#array)]. You also, don't need a separate table for each figure, and for numbers, just use math.random. Don't forget to use randomseed, though. Also, you have to filter the text, as randomly generated text must be filtered so that it is appropriate for Roblox.

More about filtering random words.

Anyway, here is your script.

math.randomseed(tick())

local Letters =
 {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}

game.Players.PlayerAdded:connect(function(Player)
    local text = "Camera Subject "
    for i = 1,5 do
        text = text..((((i/2 == math.floor(i/2)) and math.random(0,9)) or Letters[math.random(1,#Letters)]))..((i == 2 and "-") or "")
    end
    print("Working")
    wait(15)
    script.Parent.Text = text
end)
0
For some odd reason, it still doesn't work... RealRexTerm 21 — 6y
0
Never mind. Fixed it. Thanks for the script! RealRexTerm 21 — 6y
Ad

Answer this question