Issue, when I die the highlight returns false, I want it stay highlighted if it was enabled when I die and respawn. It works for the other players but not yourself.
Video:
local script:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local highlightingEnabled = false
local toggleSound = game.ReplicatedStorage.Sounds.Click
local playerGui = localPlayer.PlayerGui
local settingsGui = playerGui:WaitForChild("SettingsGui")
local frame = settingsGui:WaitForChild("Frame")
local toggleHighlight = frame:WaitForChild("ToggleHighlight")
local function createHighlight1(part)
if part:FindFirstChild("highlight") then return part:FindFirstChild("highlight") end
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.90
highlight.Color3 = Color3.fromRGB(85, 255, 127)
highlight.Name = "highlight"
highlight.Parent = part
return highlight
end
local function removeHighlights1()
for _, player in ipairs(game.Players:GetPlayers()) do
if player ~= 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 highlightPlayer1()
for _, player in ipairs(Players:GetPlayers()) do
if player ~= localPlayer then
local character = player.Character
if character then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
createHighlight1(part)
end
end
end
end
end
end
toggleHighlight.MouseButton1Click:Connect(function()
toggleSound:Play()
highlightingEnabled = not highlightingEnabled
end)
removeHighlights1()
RunService.Heartbeat:Connect(function()
if highlightingEnabled then
highlightPlayer1()
print(highlightingEnabled)
else
removeHighlights1()
print(highlightingEnabled)
end
end)