How would one save the state of the highlight so that if your character dies/respawns it will reapply it when you respawn?
script:
local player = game.Players.LocalPlayer
local highlightingEnabled = false
local toggleSound = game.ReplicatedStorage.Sounds.Click
local playerGui = player.PlayerGui
local settingsGui = playerGui:WaitForChild("SettingsGui")
local frame = settingsGui:WaitForChild("Frame")
local toggleHighlight = frame:WaitForChild("ToggleHighlight")
local function createHighlight(part)
local highlight = Instance.new("BoxHandleAdornment")
highlight.Size = part.Size + Vector3.new(0.1, 0.1, 0.1)
highlight.Adornee = part
highlight.AlwaysOnTop = true
highlight.ZIndex = 5
highlight.Transparency = 0.5
highlight.Color3 = Color3.fromRGB(85, 255, 127)
highlight.Parent = part
return highlight
end
local function removeHighlights()
highlightingEnabled = false
for _, player in ipairs(game.Players:GetPlayers()) do
if player ~= game.Players.LocalPlayer then
local character = player.Character
if character then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
for _, highlight in ipairs(part:GetChildren()) do
if highlight:IsA("BoxHandleAdornment") then
highlight:Destroy()
end
end
end
end
end
end
end
end
local function highlightPlayers()
highlightingEnabled = true
for _, player in ipairs(game.Players:GetPlayers()) do
if player ~= game.Players.LocalPlayer then
local character = player.Character
if character then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
createHighlight(part)
end
end
end
end
end
end
toggleHighlight.MouseButton1Click:Connect(function()
toggleSound:Play()
if highlightingEnabled == false then
highlightPlayers()
print("Enabled")
elseif highlightingEnabled == true then
removeHighlights()
print("Disabled")
end
end)
removeHighlights() -- default setting
I don’t care to save it when you leave the game, fyi