HI, I have been trying to make it so my custom tag has a new random tag with random characters in between the “[” and the “]” every seconds like in the screenshot
I have managed to generate a random string and added the
"["
but can’t figure out on how to add the second
"]"
. I have a reference on how it should look in the screenshot.
local Players = game:GetService("Players")
local HidePart = script.Parent
HidePart.Touched:Connect(function(Character)
local Player = Players:GetPlayerFromCharacter(Character.Parent)
if Player.Name == ("UnnamedSkilI") then
local guy = game.Workspace:FindFirstChild(Player.Name)
local Name = guy.Head.Rank.User
local Rank = guy.Head.Rank.Team
while true do
for i = 0,6,1 do
Name.Text = Name.Text .. string.char(math.random(33,126)) -- The generated text string
end
wait(1)
Name.Text = "[ " -- Adding the first one
end
script.Enabled = false
wait(60)
script.Enabled = true
Rank:Destroy()
else
end
end)
I have tried many things but can’t still do it, If anyone could help me I would really appreciate it.
If you also have some feedback on how to optimize the script that would be cool!
I would declare a variable and then just store the random string in the variable so instead do for example randomString = randomString … string.char(math.random(33,126))
and then when you have the length you want do Name.Text = “[ " … randomString … " ]”
concatenation
You can add onto a string by using .. to another item, like for Example:
local currentString = "[ "..otherstring.. " ]"
-- your strings will get added together to form a single string.
string.format()
You are able to format your strings using a specific specifier, this this case, you can use %s which is used for strings.
local currentString = string.format("[ %s ]", otherstring) -- format
-- This will give you the format of your stringm %s would be replaced with 'otherstring'
-- Alternate Version:
local currentString = ("[ %s ]"):format(otherstring) -- format
Should also be using a seperate variable instead of using the same one, so like this:
local otherstring -- Empty variable, Defaults to nil
for i = 1,6 do -- this will run 6 times instead of 7
otherstring = Text .. string.char(math.random(33,126)) -- Applies Data to Outside Variable
end
Try printing the Name.Text out and see if it returns it with both brackets or not. Maybe it is correctly displayed in the Text in the Label and it’s just a display issue. In your picture I just noticed there also seems to be no space between the bracket, which you added that in your script, and the random string so maybe its too tiny for the string?
Hello!! This does in fact work but I only get one character instead of 6 (Screenshot)
Here is what i did:
while wait(1) do
local otherstring
for i = 1,6 do
otherstring = string.char(math.random(33,126))
end
local currentString = ("[ %s ]"):format(otherstring)
Name.Text = currentString
end
script.Enabled = false
wait(60)
script.Enabled = true
Rank:Destroy()
Hello now it just doesn’t works here is the error i’m getting:
Workspace.Folder.CODENAME.HideName.ChangeName:14: attempt to concatenate nil with string - Server - ChangeName:14
00:10:12.870 Stack Begin - Studio
00:10:12.870 Script 'Workspace.Folder.CODENAME.HideName.ChangeName', Line 14 - Studio - ChangeName:14
00:10:12.870 Stack End - Studio
Here is the script
while wait(1) do
local otherstring
for i = 1,6 do
otherstring = otherstring .. string.char(math.random(33,126))
end
local currentString = ("[ %s ]"):format(otherstring)
Name.Text = currentString
end