Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you reverse a player's username?

I've seen it in LuaModelMaker's admin house, but I was wondering how I could do it. I tried this:

if script.Parent.Name == "PlayerGui" then
print('Special UI loading...')
else
script:Destroy()
local plr = game.Players.LocalPlayer
plr.PlayerAdded:connect(function()
local name = plr.Name, 6 --[[I read the variables and they said do 2 or more to swap]]
local revname = 6, plr.Name --[[ WON'T REVERSE IT!!!!]]
end)
local name = plr.Name, 6
local revname = 6, plr.Name
plr.Chatted:connect(function()
print(name.."Converting to reverse name... please wait.")
wait(2)
print(name.."Converted into"..revname".")
end)
end

can anyone say what is wrong? Thanks for reading!

2 comments

1

If I answered you question please click the 'accept answer' button on the right under my name.

0

sorry I forgot.

1 answer

✓ Accepted answer

You have many problems here.

  • The PlayerAdded event is an event of game.Players, not individual Player objects.

  • PlayerAdded events don't work well in LocalScripts. They will fire for the local player, but not anyone else.

  • name = plr.Name, 6 and revname = 6, plr.Name accomplishes absolutely nothing.

  • There is no need to define variables more than once.

  • All you're doing in the PlayerAdded event is defining two variables, but then you define them again after the PlayerAdded event, making the PlayerAdded event useless. You also have them as local variables inside the PlayerAdded event, meaning they couldn't be used outside it anyway.

  • Why would you create fake lag by delaying the script two seconds before converting the name?

  • The first if statement on line 01 it pointless; just put the script where you want it. However, it could also prevent the script from working, since LocalScripts only run inside three places, PlayerGui probably being the best in this case, but if you put it in PlayerGui, it will be destroyed, due to the if statement.


To reverse a string, you can simply use what is built into Lua: string.reverse()

local plr = game.Players.LocalPlayer

plr.Chatted:connect(function()
	print(plr.Name)
	print(string.reverse(plr.Name))
end)

string.reverse() can also be used as a method, i.e.

print(plr.Name:reverse())

1 comment

0

Thanks so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.