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

How do you reverse a player's username?

Asked by 10 years ago

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!

1
If I answered you question please click the 'accept answer' button on the right under my name. Perci1 4988 — 10y
0
sorry I forgot. TroytheDestroyer 75 — 10y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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())
0
Thanks so much! TroytheDestroyer 75 — 10y
Ad

Answer this question