local delete = game:GetService("ReplicatedStorage"):WaitForChild("Delete")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local selectionBox = Instance.new("SelectionBox")
selectionBox.Color3 = Color3.new(0, 1, 0)
selectionBox.LineThickness = 0.01
selectionBox.Parent = player.PlayerGui
local debounce = false
local isEquipped
local target
local function onActivated ()
if debounce == false then
if target and target.Name == "Deletable" and player:DistanceFromCharacter(target.Position) < 18 then
debounce = true
delete:FireServer(target)
target:Destroy()
selectionBox.Color3 = Color3.new(1, 0, 0)
target = mouse.Target
if target and target.Name == "Deletable" and player:DistanceFromCharacter(target.Position) < 18 then
selectionBox.Adornee = target
else
selectionBox.Adornee = nil
end
wait(0.1)
selectionBox.Color3 = Color3.new(0, 1, 0)
debounce = false
end
end
end
local function onEquipped ()
isEquipped = true
while isEquipped do
target = mouse.Target
if target and target.Name == "Deletable" and player:DistanceFromCharacter(target.Position) < 18 then
selectionBox.Adornee = target
else
selectionBox.Adornee = nil
end
wait(0.1)
end
end
local function onUnequipped ()
isEquipped = false
selectionBox.Adornee = nil
end
script.Parent.Activated:Connect(onActivated)
script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(onUnequipped)
COMMUNITY QUESTION
Is there a way to increase the performance of this script, if then how?
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
It seems fine to me. Are you having performance problems?
no, i just wanted it to be as best as possible, since this is a vital part of the game
while loop in onEquipped function is quite inneficient, you better use the UserInputService.InputChanged and then check if Input.UserInputType == Enum.UserInputType.MouseMovement which fires when you move the mouse, then you check the target.
Here is example, this is the most efficient way: https://pastebin.com/JXUDRvP8
Thankyou!