So, hey 'der!
I've found a script on roblox for free which helped me out. The script is used to ban people from my game. However, i'd like to get their Username too from their Userid (I ban them if their userid match from the bannedlist)
Example of the script below.
bannedplayerid = script.UserID.Value--the person to ban (userid e.g. 12345678)
banreason = script.BanReason.Value --reason for ban
anonymousbanner = false --if the banner is anonymous (e.g false)
banner = "Tom" --put whoever banned the person here
enforceban = true --if the ban is enforced (e.g true)
note = script.BanAppeal.Value --e.g. message someone to appeal
secretban = false --if when banned it displays the ban message (false) or "You have lost connection to the game" (true)
Alert = script.Parent.Alert -- Sound
Alert2 = script.Parent.Alert2 -- Sound
Username = script.Name -- Scripts name.
BanStat = script.BanStatus.Value -- If user still is banned, or that i did unban.
--------------------------------------------------------------------------------------------------------------------------------------------------------
game.Players.PlayerAdded:connect(function(instance)
wait()
if instance.UserId == bannedplayerid then
wait()
if not enforceban == false then
wait()
if secretban == false then --Secretban
wait()
if BanStat == true then --BanStat
wait()
if Alert.Playing == false then
wait()
Alert:Play()
wait()
else
end
if anonymousbanner == true then
( HERE IS THE BANLINE THAT KICKS PEOPLE )
else
( HERE IS THE BANLINE THAT KICKS PEOPLE )
end
else --BanStat
end --BanStat
else --Secretban
end --Secretban
end
end
end)
At the line where it says "( HERE IS THE BANLINE THAT KICKS PEOPLE )" i'd like to place a line that would create a message like "Dear " ..Username.. ". You have been banned" -- And more text.
I would like that Username would be the username from ID and not the name from the script.
I've done some research through google and official roblox wiki thing. But i couldn't figure it out.
It would be nice if you guys could help me :-)
EDIT: Can i also add a line that would a badge to the player by playerid?
Thanks :-)

3 comments
https://developer.roblox.com/api-reference/function/Players/GetNameFromUserIdAsync
If this solves your problem, be sure to add [Solved] to the title of your question so that people know you don't need anymore help.
Aaaaaaa why do you use wait() everywhere? Why do you use global variables? Why do you use lowercase :connect()? Why don't you merge multiple if statements into one? Your code needs a big boi rewrite xd