when I toggle highlight it turns on but it flickers off instantly for some reason. can anyone help?
video:
server:
local toggleHighlightEvent = game.ReplicatedStorage.ToggleHighlightEvent
local function highlightPlayers(player)
for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
if otherPlayer ~= player then
toggleHighlightEvent:FireClient(otherPlayer, true)
end
end
end
local function removeHighlights(player)
for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
if otherPlayer ~= player then
toggleHighlightEvent:FireClient(otherPlayer, false)
end
end
end
toggleHighlightEvent.OnServerEvent:Connect(function(player, highlightingEnabled)
if highlightingEnabled then
highlightPlayers(player)
else
removeHighlights(player)
end
end)
client:
local player = game.Players.LocalPlayer
local highlightingEnabled = false
local toggleSound = game.ReplicatedStorage.Sounds.Click
local playerGui = player.PlayerGui
local settingsGui = playerGui:WaitForChild("HighlightServerGui")
local toggleHighlight = settingsGui:WaitForChild("ToggleHighlight")
local highlightingStateKey = "HighlightingState"
local toggleHighlightEvent = game.ReplicatedStorage.ToggleHighlightEvent
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()
highlightingEnabled = not highlightingEnabled
toggleHighlightEvent:FireServer(highlightingEnabled)
if highlightingEnabled then
highlightPlayers()
print("Enabled")
else
removeHighlights()
print("Disabled")
end
end)
toggleHighlightEvent.OnClientEvent:Connect(function(player, highlightingEnabled)
if player == game.Players.LocalPlayer then
if highlightingEnabled then
highlightPlayers()
print("Enabled")
else
removeHighlights()
print("Disabled")
end
end
end)