Cube drops instantly instead of normally

Hi, i am in the middle of making a raycast based object grabbing system.
in the script everything works perfectly as they should. but whenever i stop holding my cube, the following happens:

before i send the script; this has nothing to do with customphysicalproperties, or any materia physics

Code;

Summary
task.wait() ; game:GetService("RunService").Stepped:Wait()


---Services
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local PS = game:GetService("PhysicsService")




--- Character Detection
local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")




--- Extra Useful stuff
local IS = require(game.ReplicatedStorage.InputModule)
local PosAtt = Instance.new("Attachment", workspace.Terrain)
local currentCam = workspace.CurrentCamera
local crosshair = player.PlayerGui.crosshairs.crosshair


--- Values
local value = 0
local part = nil
local part2 = nil
local canGrab = false
local align = nil
local grabbing = false
local BP = nil
local BV = nil
local door = nil

local throwForce = 40
local rayDis = 20
local checkAbove = nil
local checkBelow = nil



--Extra FUnctişon

local function getdistance(b1, b2)
  return (b1 - b2).Magnitude
end


--Change Collision Group
for i, i in pairs(char:GetDescendants()) do
  if i:IsA("BasePart") then
    PS:GetCollisionGroupId("players")
    i.Transparency = 1
  end
end




local lastpos = Vector3.new()

--MAIN FUNCTIONS

local function grab()
  if grabbing == false then grabbing = true end
	grabbing = true
	part.CollisionGroupId = PS:GetCollisionGroupId("objects")

end

local function ungrab()
  if grabbing == true then grabbing = false end
	grabbing = false
  part.CollisionGroupId = 0
  
end
----------------

local raycastParamscheck = RaycastParams.new()
local grabcastParamscheck = RaycastParams.new()
grabcastParamscheck.FilterType = Enum.RaycastFilterType.Blacklist
grabcastParamscheck.FilterDescendantsInstances = {}

local tempTable = {}
for i, v in pairs(game:GetDescendants()) do
	if string.find(v.Name, "cube") or string.find(v.Name, "HumanoidRootPart") then
		table.insert(tempTable, v)
	end
end

grabcastParamscheck.FilterDescendantsInstances = {table.unpack(tempTable)}

local vf = nil
local pos = nil



	RS.RenderStepped:Connect(function()
	  local livePosHRP = char.HumanoidRootPart
	  local RayCast2 = Ray.new(currentCam.CFrame.Position, currentCam.CFrame.LookVector.Unit*15)
		--part2 = workspace:FindPartOnRay(RayCast2, char)


		local origin = currentCam.CFrame.Position
		local direction = currentCam.CFrame.LookVector.Unit*5
		local grabCast = workspace:Raycast(origin, direction, grabcastParamscheck)
	  pos = grabCast and grabCast.Position or origin+direction
		local nor = grabCast and grabCast.Normal or  -direction.Unit
		
		
	  	

	  if grabbing then
	    local BaseCFrame = currentCam:GetRenderCFrame()
		--	print(part.AssemblyLinearVelocity)
		if part and part.Anchored == false and string.find(part.Name, "cube") and part:FindFirstChildWhichIsA("Attachment") then
				grab()
				if grabbing == true then
					part.Position = pos
					part.CFrame = CFrame.lookAt(pos, pos + Vector3.new(nor.X ,0, nor.Z))
					

					--	print(grabCast.Instance)
				else
					
		
					
					ungrab()
				end
	    end
	    
	    lastpos = livePosHRP.Position
	    
	    if part and getdistance(part.Position, livePosHRP.Position) > 10 then
	    --  ungrab()
	    end
	  end
	  
	 -- checkAbove = workspace:Raycast(char.HumanoidRootPart.Position, Vector3.new(0,((char.HumanoidRootPart.Size.Y + char.HumanoidRootPart.Size.Y)) + 0.15,0), raycastParamscheck)
	 -- checkBelow = workspace:Raycast(char.HumanoidRootPart.Position, Vector3.new(0,(-(char.HumanoidRootPart.Size.Y)) + 1, 0), raycastParamscheck)
	  
	end)




	UIS.InputBegan:Connect(function(input, gameProcessedEvent)
		
		
	  if input.KeyCode == Enum.KeyCode.E then
	    print(grabcastParamscheck.FilterDescendantsInstances)
	    local RayCast = Ray.new(currentCam.CFrame.Position, currentCam.CFrame.LookVector.Unit*15)
	    part = workspace:FindPartOnRay(RayCast,char)
	    
	    if part and part.Anchored == false and part:FindFirstChildWhichIsA("Attachment") and string.find("cube", part.Name) then
	      if canGrab == false then canGrab = true else canGrab = false end
	      
				if canGrab == true then
					Part.Anchored = true

	        grab()
	      end
	      
				if canGrab == false or not part or char.Humanoid.Health == 0 then

					Part.Anchored = false
	        ungrab()
	        
	        elseif part or not part or part == nil then
	      end
	    end
	    
	    end
    ---------------------------------------------------------------
    ---------------------------------------------------------------
    ---------------------------------------------------------------
    
   
  
  if input.UserInputType == Enum.UserInputType.MouseButton1 then       
    pull()
  end
  
  if input.UserInputType == Enum.UserInputType.MouseButton2 then       
    push()
  end
 
end)

i seriously don’t understand what im doing wrong.

  • sorry for the ultra messy script
  • i have tried applying a vectorforce while grabbing the cube
1 Like

perhaps remove the line part.Position = pos before you set the parts CFrame? Or did you also make a mistake and meant to put pos = part.Position?

the part is set the cube’s cframe is for the rotation when i grab it
plus, pos is the positin of the ray im casting to put the cube in it, so replacing it just made that cube’s position /(im really sorry for my english here let me know if you cant understand this)

tl;dr cframe is for cube’s rotation and pos is raycast’s position so replacing it didnt move the cube

fixed with the help of homemade_meal