Summary: When a player is holding a flag, they have selection boxes put into every one of their body parts. If they capture the flag, the selection boxes should be removed
Script to do action:
local nameh = ""--Stores flag holder's name function touchEnter() if script.Parent.Parent.Name ~= "BlueFlag" then nameh = script.Parent.Parent.Name workspace.CapturesChecker.BlueFlagHolder.Value = nameh--Gets flag holder's name workspace.CapturesChecker.Main.Disabled = false--Disables a script end end function onPropChange(obj, parent) if parent.Name == "BlueFlag" or parent == workspace then--If the flag is back at its stand or in workspace, then workspace.CapturesChecker.BlueFlagHolder.Value = "None"--Ignore this stuff workspace.CapturesChecker.Main.Disabled = false local c = game.Players[nameh].Character--This is where the problem starts c.Head.SelectionBox:Destroy()--These are lines to destroy the selection boxes, however they still exist c.Torso.SelectionBox:Destroy() c["Left Arm"].SelectionBox:Destroy() c["Right Arm"].SelectionBox:Destroy() c["Left Leg"].SelectionBox:Destroy() c["Right Arm"].SelectionBox:Destroy() end end script.Parent.Equipped:connect(touchEnter) script.Parent.AncestryChanged:connect(onPropChange)
Problem: The selection boxes aren't destroyed. The event is fired (GUIs change after the event is fired) but the selection boxes still exist within the player's body parts. What am I doing wrong and how can it be fixed?
Destroy()
function sets the Parent property of a part as nil and the Locked propety of it as true. But a SelectionBox instance does not have the Locked property. So, you must to set your selection boxes' parent property again. To say goodbye to them, you should use nil, which means "nothing".
So, where you have
c.Head.SelectionBox:Destroy()--These are lines to destroy the selection boxes, however they still exist c.Torso.SelectionBox:Destroy() c["Left Arm"].SelectionBox:Destroy() c["Right Arm"].SelectionBox:Destroy() c["Left Leg"].SelectionBox:Destroy() c["Right Arm"].SelectionBox:Destroy()
You should have
c.Head.SelectionBox.Parent = nil c.Torso.SelectionBox.Parent = nil c["Left Arm"].SelectionBox.Parent = nil c["Right Arm"].SelectionBox.Parent = nil c["Left Leg"].SelectionBox.Parent = nil c["Right Arm"].SelectionBox.Parent = nil
PS: Not sure if i'm correct.