Proximity Swap

Script

local folder = script.Parent


local function checkTool(plr)

local tool = plr.Character:FindFirstChildWhichIsA("Tool")

if not tool then

tool = plr.Backpack:FindFirstChildWhichIsA("Tool")

end

return tool

end


local function putDown(obj, tool)

tool.Handle.ProximityPrompt.Enabled = true

tool.Parent = folder

tool.Handle.Anchored = true

tool.Handle.Position = obj.Main.Position

if tool.Handle:FindFirstChild("TouchInterest") then

tool.Handle.TouchInterest:Destroy()

end

tool.Handle.Name = "Main"

end


local function pickUp(plr, obj)

obj.Main.ProximityPrompt.Enabled = false

obj.Main.Anchored = false

obj.Main.Name = "Handle"

obj.Parent = plr.Character

end



for _, obj in pairs(folder:GetChildren()) do

if obj:IsA('Tool') then

obj.Main.ProximityPrompt.Triggered:Connect(function(plr)

local tool = checkTool(plr)

if tool then

putDown(obj, tool)

pickUp(plr, obj)

else

pickUp(plr, obj)

end

end)

end

end