So I recently discovered a new component called Highlight, and it looks amazing.
And I made a localScript in startercharacterscripts is when a keybind is clicked, this highlight:
will be cloned from lighting to all the players model, then when clicked again, they will be destroyed.
It is a simple script, so my script goes like this:
-Keybind click
-Fire server
-If is a player
-Then clone KenHi1 from lighting to found players
-If is a humanoid but not a player, then ignore
-Keybind clicks again with the highlight on, then fire another server
-Destroy all highlights in player models
It doesn’t work like that, and I am pretty clueless.
Any help is appreciated!
Do you want hightlight to be visible to client only?
if so:
local uis = game:GetService('UserInputService')
local enabled = false
local function highlight(bool)
for i,v in pairs(workspace:GetDescendants()) do
if v:FindFirstChild('Humanoid') then
if v:IsA('Model') then
if v.Name == game.Players.LocalPlayer.Name then return end
if bool == true then
if not v:FindFirstChild('Highlight') then
local highlight = Instance.new('Highlight')
highlight.Parent = v
--edit the highlight or just clone it from somewhere else lol
end
elseif bool == false then
if v:FindFirstChild('Highlight') then
v.Highlight:Destroy()
end
end
end
end
end
end
uis.InputBegan:Connect(function(input,ignore)
if input.KeyCode == Enum.KeyCode.L and not ignore then
if not enabled then
enabled = not enabled
highlight(true)
else
enabled = not enabled
highlight(false)
end
end
end)
Otherwise:
Local script:
local uis = game:GetService('UserInputService')
local enabled = false
local event = game.ReplicatedStorage.Show
uis.InputBegan:Connect(function(input,ignore)
if input.KeyCode == Enum.KeyCode.L and not ignore then
if not enabled then
enabled = not enabled
event:FireServer(enabled)
else
enabled = not enabled
event:FireServer(enabled)
end
end
end)
Server Script:
local function highlight(plr,bool)
for i,v in pairs(workspace:GetDescendants()) do
if v:FindFirstChild('Humanoid') then
if v:IsA('Model') then
if v.Name == plr.Name then return end
if bool == true then
if not v:FindFirstChild('Highlight') then
local highlight = Instance.new('Highlight')
highlight.Parent = v
end
elseif bool == false then
if v:FindFirstChild('Highlight') then
v.Highlight:Destroy()
end
end
end
end
end
end
game.ReplicatedStorage.Show.OnServerEvent:Connect(function(plr,bool)
if plr then
highlight(plr,bool)
end
end)
If that’s not what you needed or if you didn’t understand some part of it then let me know