Here is my script
local function GetClosestPlayer()
local LowestDistance = math.huge
local ClosestCharacter = nil
local Characters = {}
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Character ~= nil and v ~= game.Players.LocalPlayer then
table.insert(Characters, v.Character)
end
end
for i,v in pairs(Characters) do
if v ~= nil then
if v:FindFirstChild("HumanoidRootPart") then
local InitialDis = (v.HumanoidRootPart.Position - game.Workspace.CurrentCamera.CFrame.p).magnitude
local Ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p, (mouse.Hit.p - game.Workspace.CurrentCamera.CFrame.p).unit * InitialDis)
local Part,Position = game.Workspace:FindPartOnRay(Ray, game.Workspace)
local FinalDifference = math.floor((Position - v.HumanoidRootPart.Position).magnitude)
if FinalDifference < LowestDistance then
ClosestCharacter = v
LowestDistance = FinalDifference
end
end
end
end
local ClosestPlayer = game.Players:GetPlayerFromCharacter(ClosestCharacter)
if ClosestPlayer ~= nil then
return ClosestPlayer.name
end
I want to return ClosestPlayer.name as a string so that I can print their name. Please help!

4 comments
Huh? I think you misunderstood my question.
What did you want your question to be?
I was wondering how to return something in quotation marks so that I can print it, is it possible?
k