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 :-)
To get the name of a player from the UserId, You can use the built-in function, Players:GetPlayerByUserId(Player.UserId) which will return the name of the player with the UserId you passed into the brackets.
Use game:GetService("Players"). An example of this is:
local Players = game:GetService("Players") local function getPlayerByUserId(userId) for _, player in pairs(Players:GetPlayers()) do if player.UserId == userId then return player end end end