Dragdetector highlight

So I’m using the built in roblox dragdetector how can I make it so if I drag a highlight appears? (I’m using the built in highlight too)

This is just an example script you can add on to it and make it more efficient if you have any questions feel free to ask

script.Parent.DragDetector.DragStart:Connect(function()
	local highlight = Instance.new("Highlight")
	highlight.Parent = script.Parent
end)

script.Parent.DragDetector.DragEnd:Connect(function()
	script.Parent.Highlight:Destroy()

end)

or

local highlight = script.Parent.Highlight
script.Parent.DragDetector.DragStart:Connect(function()
	highlight.Enabled = true
end)

script.Parent.DragDetector.DragEnd:Connect(function()
	highlight.Enabled = false
end)

Hey I was wondering is it a localscript or a script and where will I place it I apologize I’m not the best at scripting I have learned some basics.

And do I have to enable or disable the highlight?

This code should be ran on a LocalScript.

When the .DragStart event fires, the Highlight will be enabled.
When the .DragEnded event fires, the Highlight will be disabled.

I tried the first option but it doesn’t seem to work its localscript and its inside the part

the script:

script.Parent.DragDetector.DragStart:Connect(function()
local highlight = Instance.new(“Highlight”)
highlight.Parent = script.Parent
end)

script.Parent.DragDetector.DragEnd:Connect(function()
script.Parent.Highlight:Destroy()

end)

LocalScripts will not work if they’re not parented to the right object.

LocalScripts should be parented to the following:

  • StarterGui
  • StarterPlayerScripts
  • StarterCharacterScripts
  • Backpack

I recommend parenting it to the StarterPlayerScripts.

You’ll have to change the DragDetectors’ path.

local dragDetector = nil -- Path to your DragDetector.

What do you mean exactly by dragdetector path if you could explain me it more simplified i’m not that good at scripting i apologize for the time waste

-- Examples of paths
local myDetector = workspace.DragDetector -- This will go through Workspace, then to the DragDetector

local myDetector_2 = game.Players["lillsbit"].Backpack -- This will go through the Players service, then to your username, then to your Backpack.