function waitForChild(parent, childName) while true do local child = parent:FindFirstChild(childName) if child then return child end parent.ChildAdded:wait() end end print("Loading telekinesis script...") bin = script.Parent player = bin.Parent.Parent damage = waitForChild(bin, "BrickScript") local debounce = false local TKCF = nil local grValue = Instance.new("NumberValue") grValue.Value = 10.5 grValue.Name = "Grab Radius" grValue.archivable = false grValue.Parent = bin local tkrValue = Instance.new("NumberValue") tkrValue.Value = 32 tkrValue.Name = "Telekinesis Radius" tkrValue.archivable = false tkrValue.Parent = bin local rldValue = Instance.new("NumberValue") rldValue.Value = 1 rldValue.Name = "Reload Time" rldValue.archivable = false rldValue.Parent = bin local maxFValue = Instance.new("NumberValue") maxFValue.Value = 1100400 maxFValue.Name = "Max Force" maxFValue.archivable = false maxFValue.Parent = bin --TKRadius = 32 TKPos = Vector3.new(0, 0, 0) local totalMass = 0 function brickDistance(obj, pos) if (obj.Shape == 0) then return ((pos - obj.Position).magnitude - obj.Size.magnitude / 2) else local relPos = obj.CFrame:pointToObjectSpace(pos) local nearPos = relPos if (nearPos.x * 2 > obj.Size.x) then nearPos = Vector3.new(obj.Size.x / 2, nearPos.y, nearPos.z) elseif (nearPos.x * 2 < -obj.Size.x) then nearPos = Vector3.new(-obj.Size.x / 2, nearPos.y, nearPos.z) end if (nearPos.y * 2 > obj.Size.y) then nearPos = Vector3.new(nearPos.x, obj.Size.y / 2, nearPos.z) elseif (nearPos.y * 2 < -obj.Size.y) then nearPos = Vector3.new(nearPos.x, -obj.Size.y / 2, nearPos.z) end if (nearPos.z * 2 > obj.Size.z) then nearPos = Vector3.new(nearPos.x, nearPos.y, obj.Size.x / 2) elseif (nearPos.z * 2 < -obj.Size.z) then nearPos = Vector3.new(nearPos.x, nearPos.y, -obj.Size.x / 2) end return (nearPos - relPos).magnitude end end function drop() if TKCF ~= nil then print("Telekinesis: Dropping parts...") TKCF:Remove() TKCF = nil end end function grab(pos, obj, harmless, MaxForce) if (obj:FindFirstChild("Telekinesis Influence") ~= nil) then -- Prevent muliple grabs return end if (obj.className == "Part") or (obj.className == "Seat") or (obj.className == "SpawnLocation") then if (brickDistance(obj, pos) < grValue.Value) and (not obj.Anchored) and ((h == nil) or (h.Health <= 0)) then local harm = obj:FindFirstChild("No TK Damage") local oldScript = obj:FindFirstChild("BrickScript") if oldScript ~= nil then oldScript:Remove() end -- When possible, make objects be broken off from others. (But not from other parts that are grabbed) --obj:BreakJoints() --local tag = Instance.new("ObjectValue") --tag.Name = "creator" --tag.Value = player --tag.Parent = obj local damageCopy = damage:Clone() damageCopy.Disabled = false damageCopy.archivable = false if harmless or (harm ~= nil) then local noDamage = Instance.new("BoolValue") noDamage.Name = "No Damage" noDamage.Parent = damageCopy end local tag2 = Instance.new("ObjectValue") tag2.Name = "TK CFrame" tag2.Value = TKCF tag2.Parent = damageCopy damageCopy.Parent = obj -- Now adjust brick force to be within MaxForce local mass = obj:GetMass() totalMass = totalMass + mass delay(0.1, function() if (totalMass * 1400 > MaxForce) and (mass * MaxForce / totalMass < 91700) then local bp = obj:FindFirstChild("Telekinesis Influence") if (bp ~= nil) then bp.maxForce = mass * Vector3.new(1, 1, 1) * MaxForce / totalMass end end end) end elseif ((obj.className == "Workspace") or (obj.className == "Model") or (obj.className == "Tool") or (obj.className == "Hat")) and (obj ~= player.Character) then local h = obj:FindFirstChild("Humanoid") local harm = obj:FindFirstChild("No TK Damage") if (h == nil) or (h.Health <= 0) then local list = obj:GetChildren() for x = 1, #list do grab(pos, list[x], (harm ~= nil) or harmless, MaxForce) end end end end function onButton1Down(mouse) if debounce then return end local newDamage = bin:FindFirstChild("BrickScript") if newDamage ~= nil then damage = newDamage end drop() local char = player.Character if char ~= nil then local human = char.Humanoid if (human == nil) or (human.Health <= 0) then return end else return end TKCF = Instance.new("CFrameValue") TKCF.Name = "TK CFrame" TKCF.Parent = bin --if (mouse.Target ~= nil) then local relPos = mouse.Hit.p - player.Character.PrimaryPart.Position if (relPos.magnitude > tkrValue.Value) then relPos = relPos.unit * tkrValue.Value end totalMass = 0 print("Telekinesis: Grabbing parts...") grab(player.Character.PrimaryPart.Position + relPos, workspace, false, maxFValue.Value) --end mouse.Icon = "rbxasset://textures\\GunWaitCursor.png" end function onButton1Up(mouse) if (TKCF ~= nil) then drop() debounce = true wait(rldValue.Value) mouse.Icon = "rbxasset://textures\\GunCursor.png" debounce = false end end function updatePos(mouse) if (TKCF ~= nil) then local char = player.Character if char ~= nil then local human = char.Humanoid if (human == nil) or (human.Health <= 0) then drop() return end else drop() return end mouseCF = mouse.Hit TKPos = mouseCF.lookVector * tkrValue.Value if TKPos.y < -4.5 then TKPos = TKPos * Vector3.new(1, 0, 1) + Vector3.new(0, -4.5, 0) end TKPos = TKPos + player.Character.PrimaryPart.Position TKCF.Value = CFrame.new(TKPos, TKPos + mouseCF.lookVector) end end function onSelected(mouse) print("Telekinesis selected") mouse.Icon = "rbxasset://textures\\GunCursor.png" mouseConnection = mouse.Button1Down:connect(function() onButton1Down(mouse) end) mouse.Button1Up:connect(function() onButton1Up(mouse) end) mouse.Idle:connect(function() updatePos(mouse) end) mouse.Move:connect(function() updatePos(mouse) end) end function onDeselected() if (mouseConnection ~= nil) then mouseConnection:disconnect() end drop() end selectionConnection = bin.Selected:connect(onSelected) bin.Deselected:connect(onDeselected)