Idk how to destroy a highlight instance. Tried :Destroy(), tried = nil, idk. how do you do it?
The info:
local mark = Instance.new("Highlight", v.Parent)
mark.FillTransparency = 1
mark.OutlineColor = Color3.new(1, 1, 0)
mark = nil
pls help.
Idk how to destroy a highlight instance. Tried :Destroy(), tried = nil, idk. how do you do it?
The info:
local mark = Instance.new("Highlight", v.Parent)
mark.FillTransparency = 1
mark.OutlineColor = Color3.new(1, 1, 0)
mark = nil
pls help.
Make sure .Adornee is nil, but I believe :Destroy should work fine. If it doesn’t I would post a bug report.
mark.Parent = nil
Basically another way to destroy an object.
----------------- character limit count ------
just do mark:Destroy()
. Also could you provide more detail on what’s happening when you do :Destroy()
. Also setting parent as nil
isn’t necessarily a good idea. Yes it will clean up the instance during the next cycle of the garbage collector, but afaik events bound to the instance aren’t disconnected automatically when that happens. So it’s better to call :Destroy
whenever possible as it disconnects all connections and sets the parent to nil
This is what happens when I do destroy.
I cannot set the Parent to nil sadly, because the highlight is given to a player.
This is because the variable can’t be reached in this area due to its scope. Can you send us the whole script?
Despite Adornee being nil, it still does’nt work. If it’s any help, this is the full script:
if hitboxneedstobeseen == false then
local x = Instance.new("Part", workspace)
x.Name = "Hitbox"
x.BrickColor = BrickColor.new("Really red")
x.Size = Vector3.new(4, 4, 4)
x.CanCollide = false
x.Transparency = 1
local w = Instance.new("Weld", x)
w.Part0 = Character.HumanoidRootPart
w.Part1 = x
w.C1 = CFrame.new(0, 0, 2)
for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
local mark = Instance.new("Highlight", v.Parent)
mark.FillTransparency = 1
mark.OutlineColor = Color3.new(1, 1, 0)
damageevent1:FireServer(v)
mark.Adornee = nil
end
end
mark:Destroy()
Character.Humanoid.WalkSpeed = 10
sprintdebounce = false
wait(1)
x:Destroy()
wait(1)
debounce = false
else
local x = Instance.new("Part", workspace)
x.Name = "Hitbox"
x.BrickColor = BrickColor.new("Really red")
x.Size = Vector3.new(4, 4, 4)
x.CanCollide = false
x.Transparency = 0.5
local w = Instance.new("Weld", x)
w.Part0 = Character.HumanoidRootPart
w.Part1 = x
w.C1 = CFrame.new(0, 0, 2)
for i, v in pairs(workspace:GetPartsInPart(x)) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= Character and v.Parent:FindFirstChild("Hit"..Player.Name) == nil then
local x = Instance.new("IntValue", v.Parent)
x.Name = "Hit"..Player.Name
game.Debris:AddItem(x, 1)
damageevent1:FireServer(v)
end
end
wait(1)
x:Destroy()
wait(1)
debounce = false
end
Yep. You’ve declared the variable mark
inside a condition. mark
cannot be accessed by areas of the script outside of this area, and so when you try to destroy it, mark
doesn’t exist. What you want to do instead is to create mark
outside this area in the global scope, but set its adornee inside the global scope.
I already deleted the Adornee part because someone suggested it and it did’nt work. How would I put it outside the area? Do you mean like creating a remote event?
I’m pretty sure it doesn’t set the parent to nil. Just like how you do script.Parent = workspace
; it sets the script’s parent to workspace and doesn’t change the original parent of the script. This does the same thing:
It sets the parent of mark to nil (not the player).