can you optimize this roblox lua script for better performance? local Players =…
- User
can you optimize this roblox lua script for better performance?
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService")
local function CreateNameTag(Player) if Player.Character and not Player.Character:FindFirstChild("NameTag") then -- local billboardGui = Instance.new("BillboardGui", Player.Character) -- billboardGui.Name = "NameTag" -- billboardGui.Size = UDim2.new(0, 100, 0, 50) -- billboardGui.StudsOffset = Vector3.new(0, 2, 0) -- billboardGui.Adornee = Player.Character:FindFirstChild("Head") or Player.Character:FindFirstChildWhichIsA("BasePart") -- billboardGui.AlwaysOnTop = true if Player.Character ~= nil and Player.Character:FindFirstChild("Humanoid") ~= nil and Player.Character:FindFirstChild("HumanoidRootPart") ~= nil and Player.Character.Humanoid.Health > 0 and Player.Character:FindFirstChild("Head") ~= nil then local Target2dPosition, IsVisible = workspace.CurrentCamera:WorldToViewportPoint(Player.Character.HumanoidRootPart.Position) local scale_factor = 1 / (Target2dPosition.Z * math.tan(math.rad(workspace.CurrentCamera.FieldOfView * 0.5)) * 2) * 100 local width, height = math.floor(40 * scale_factor), math.floor(60 * scale_factor)
codelocal textLabel = Drawing.new("Text") textLabel.Visible = IsVisible textLabel.Size = 13 textLabel.Text = Player.Name.." "..math.floor((workspace.CurrentCamera.CFrame.p - Player.Character.HumanoidRootPart.Position).magnitude).."m" textLabel.Position = Vector2.new(Target2dPosition.X, Target2dPosition.Y - height * 0.5 + -15) textLabel.Center = true textLabel.Color = Color3.fromRGB(255, 255, 255) -- White color for the text textLabel.Outline = false textLabel.OutlineColor = Color3.fromRGB(0, 0, 0) textLabel.Font = 2 endend
local function CreateHighlight(Player) if Player ~= Players.LocalPlayer and Player.Character and not Player.Character:FindFirstChild("Highlight") then Instance.new("Highlight", Player.Character) CreateNameTag(Player) -- Add this line to create the name tag end end
local function UpdateHighlight(Player, HighlightColor) if Player ~= Players.LocalPlayer and Player.Character and Player.Character:FindFirstChild("Highlight") then Player.Character.Highlight.FillColor = HighlightColor end end
local function ApplyChams() local LocalPlayer = Players.LocalPlayer local roles = ReplicatedStorage:FindFirstChild("GetPlayerData", true):InvokeServer()
- Assistant