Problem with grab script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to make a grab script so I can grab parts and move them around. (Like in the cook burger game)

  1. What is the issue? Include screenshots / videos if possible!

I can move the part but the part is not following me.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Search.

I don’t speak English very good so I hope you know what I want.

Here is the code I am using:

local UIS = game:GetService("UserInputService")

repeat wait() until game.Players.LocalPlayer.Character ~= nil

local LocalPlayer = game.Players.LocalPlayer

local Mouse = LocalPlayer:GetMouse()

local MouseTarget

local Folder = script.Parent

local Range = Folder.RangeValue

local NewBodyPosition = Instance.new("BodyPosition")

local Grabing = false

function Grab()

Grabing = true

MouseTarget = Mouse.Target

end

function UnGrab()

Grabing = false

MouseTarget = nil

NewBodyPosition.Parent = nil

end

UIS.TouchTap:Connect(Grab)

Mouse.Button1Down:Connect(Grab)

UIS.TouchEnded:Connect(UnGrab)

Mouse.Button1Up:Connect(UnGrab)

NewBodyPosition.Parent = MouseTarget

game:GetService("RunService").Heartbeat:Connect(function()

if Grabing == true then

NewBodyPosition.MaxForce = Vector3.new(Folder.ForceValue.Value,Folder.ForceValue.Value,Folder.ForceValue.Value)

NewBodyPosition.Parent = MouseTarget

local CF = CFrame.new(LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Position, Mouse.Hit.Position)

local Distance = (LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Position - MouseTarget.Position).Magnitude

NewBodyPosition.Position = CF.Position + CF.LookVector * Distance

NewBodyPosition.D = 550

end

end)
1 Like