Heres what I tried but it failed for me...
On = true script.Parent.MouseButton1Down:connect(function () if On == false then On = true Tools = script.Parent.Parent.Parent.Parent.Character:GetChildren() for i = 1,#Tools do if Tools[i].className == "Tool" then Tools[i].Parent = script.Parent.Parent.Parent.Parent.Backpack end end Connection = script.Parent.Parent.Parent.Parent.Character.ChildAdded:connect(function (c) if c.className == "Tool" then c.Parent = script.Parent.Parent.Parent.Parent.Backpack end end) F = Instance.new("ForceField",script.Parent.Parent.Parent.Parent.Character) else On = false F:Remove() Connection:connect() end end)
I find that using a bool value works better than using an in-script true/false value. Replace On
with something like this:
(First insert a bool value into the script called On
)
local On = script:WaitForChild("On")
There you go, that was your only problem! I used to run into the same issue. Hope this helps.
Now I see what happened... This is the fixed version...
On = false script.Parent.MouseButton1Down:connect(function () if On == false then On = true Tools = script.Parent.Parent.Parent.Parent.Character:GetChildren() for i = 1,#Tools do if Tools[i].className == "Tool" then Tools[i].Parent = script.Parent.Parent.Parent.Parent.Backpack end end Connection = script.Parent.Parent.Parent.Parent.Character.ChildAdded:connect(function (c) if c.className == "Tool" then c.Parent = script.Parent.Parent.Parent.Parent.Backpack end end) F = Instance.new("ForceField",script.Parent.Parent.Parent.Parent.Character) else On = false F:Remove() Connection:disconnect() end end)