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

How would i change a players name though a script?

	local commands = {}

	local admins = {
		"MAD_DENISDAILY2";
		"poopfartbarf1130";
	"Mickeyrus1";
	"andrust51";
	}

	local prefix = "/"

	local function findPlayer(name)
		
		for _, player in pairs(game.Players:GetPlayers()) do
			if string.lower(player.Name) == name then
				return player
			end
		end
		
		return nil
		
	end

	local function isAdmin(player)
		for _, v in pairs(admins) do
			if v == player.Name then
				return true
			end
		end
		
		return false
	end

	commands.tp = function (sender, arguments)
		
		print("TP Function fired by "..sender.Name)
		
		for _, playerName in pairs(arguments) do
			print(playerName)
		end
		
		local playerToTeleportName = arguments[1]
		local playerToTeleportName = arguments[2]
		
		if playerToTeleportName and playerToTeleportName then
			local plrToTP = findPlayer(playerToTeleportName)
			local plrToTPto = findPlayer(playerToTeleportName)
			
			if plrToTP and plrToTPto then
				plrToTP.Character.HumanoidRootPart.CFrame = plrToTPto.Character.HumanoidRootPart.CFrame
				print("Successfully moved!")
			end
		end
		
	end

	commands.speed = function(sender, arguments)
		
		print("Speed command fired by "..sender.Name)
		
		local playerToGiveSpeedTo = arguments[1]
		local amountOfSpeedToGive = arguments[2]
		
		if playerToGiveSpeedTo then
			local plr = findPlayer(playerToGiveSpeedTo)
			
			if plr then
				plr.Character.Humanoid.WalkSpeed = tonumber(amountOfSpeedToGive)
				print(playerToGiveSpeedTo.." was given Walkspeed "..amountOfSpeedToGive)
			end		
		end
	end

	commands.kill = function(sender, arguments)
		
		print("Kill command fired by "..sender.Name)
		
		local playerToKill = arguments[1]
		
		if playerToKill then
			local plr = findPlayer(playerToKill)
			
			if plr then
				plr.Character.Humanoid.Health = 0
				print(playerToKill.." was killed by "..sender.Name)
			end
		end
	end

commands.health = function(sender, arguments)
	
	print("Health command was fired by "..sender.Name)
	
	local playerToGiveHealthTo = arguments[1]
	local amountOfHealthToGive = arguments[2]
	
	if playerToGiveHealthTo then
		local plr = findPlayer(playerToGiveHealthTo)
		
		if plr then
			plr.Character.Humanoid.MaxHealth = tonumber(amountOfHealthToGive)
			plr.Character.Humanoid.Health = tonumber(amountOfHealthToGive)
			print(playerToGiveHealthTo.." was given "..amountOfHealthToGive)
		end
	end
end

commands.name = function(sender, arguments)
	
	print("Name command was fired by "..sender.Name)
	
	local playerToName = arguments[1]
	local nameToGive = arguments[2]
	
	if playerToName then
		local plr = findPlayer(playerToName)
		
		if plr then
			-- here i dont know how to
		end
	end
end

	game.Players.PlayerAdded:Connect(function(player)
		player.Chatted:Connect(function(message,recipient)
			if isAdmin(player) then
				message = string.lower(message)
				
				local splitString = message:split(" ")
				
				local slashCommand = splitString[1]
				
				local cmd = slashCommand:split(prefix)
				
				local cmdName = cmd[2]
				
				if commands[cmdName] then
					
					local arguments = {}
					
					for i = 2, #splitString, 1 do
						table.insert(arguments,splitString[i])
					end
					
					commands[cmdName](player,arguments)
					
					end
					
				
			end
		end)
	end)

1 answer

✓ Accepted answer
local commands = {}

local admins = {
	"MAD_DENISDAILY2";
	"poopfartbarf1130";
	"Mickeyrus1";
	"acediamondn123";
}

local prefix = "/"

local function findPlayer(name)

	for _, player in pairs(game.Players:GetPlayers()) do
		if string.lower(player.Name) == name then
			return player
		end
	end

	return nil

end

local function isAdmin(player)
	for _, v in pairs(admins) do
		if v == player.Name then
			return true
		end
	end

	return false
end

commands.tp = function (sender, arguments)

	print("TP Function fired by "..sender.Name)

	for _, playerName in pairs(arguments) do
		print(playerName)
	end

	local playerToTeleportName = arguments[1]
	local playerToTeleportName = arguments[2]

	if playerToTeleportName and playerToTeleportName then
		local plrToTP = findPlayer(playerToTeleportName)
		local plrToTPto = findPlayer(playerToTeleportName)

		if plrToTP and plrToTPto then
			plrToTP.Character.HumanoidRootPart.CFrame = plrToTPto.Character.HumanoidRootPart.CFrame
			print("Successfully moved!")
		end
	end

end

commands.speed = function(sender, arguments)

	print("Speed command fired by "..sender.Name)

	local playerToGiveSpeedTo = arguments[1]
	local amountOfSpeedToGive = arguments[2]

	if playerToGiveSpeedTo then
		local plr = findPlayer(playerToGiveSpeedTo)

		if plr then
			plr.Character.Humanoid.WalkSpeed = tonumber(amountOfSpeedToGive)
			print(playerToGiveSpeedTo.." was given Walkspeed "..amountOfSpeedToGive)
		end     
	end
end

commands.kill = function(sender, arguments)

	print("Kill command fired by "..sender.Name)

	local playerToKill = arguments[1]

	if playerToKill then
		local plr = findPlayer(playerToKill)

		if plr then
			plr.Character.Humanoid.Health = 0
			print(playerToKill.." was killed by "..sender.Name)
		end
	end
end

commands.health = function(sender, arguments)

	print("Health command was fired by "..sender.Name)

	local playerToGiveHealthTo = arguments[1]
	local amountOfHealthToGive = arguments[2]

	if playerToGiveHealthTo then
		local plr = findPlayer(playerToGiveHealthTo)

		if plr then
			plr.Character.Humanoid.MaxHealth = tonumber(amountOfHealthToGive)
			plr.Character.Humanoid.Health = tonumber(amountOfHealthToGive)
			print(playerToGiveHealthTo.." was given "..amountOfHealthToGive)
		end
	end
end

commands.name = function(sender, arguments)

	print("Name command was fired by "..sender.Name)

	local playerToName = arguments[1]
	local nameToGive = arguments[2]

	if playerToName then
		local plr = findPlayer(playerToName)

		if plr then
			
			local character = plr.Character
			local Humanoid = character:WaitForChild("Humanoid")
			Humanoid.DisplayName = arguments[2]
			
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message,recipient)
		if isAdmin(player) then
			message = string.lower(message)

			local splitString = message:split(" ")

			local slashCommand = splitString[1]

			local cmd = slashCommand:split(prefix)

			local cmdName = cmd[2]

			if commands[cmdName] then

				local arguments = {}

				for i = 2, #splitString, 1 do
					table.insert(arguments,splitString[i])
				end

				commands[cmdName](player,arguments)

			end


		end
	end)
end)

give me win win

2 comments

0

pro

0

lol what

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