I’m developing a grab system for my game, but the arms lag behind the player, and the grabbing lacks force. Even when the object is massless, the body doesn’t attempt to pick it up, and there is a noticeable gap between the hands and the grabbed object.
would really appreciate you feedback on how to fix the problems and how i could make this better
Grabbing not being aligned to the object:
arms seem to be disconnected from the body
https://gyazo.com/f3ac5feba4b385919d276ba350da050c
Setup Script:
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
c:WaitForChild("Humanoid").BreakJointsOnDeath = false
print("hgftyguhjkl")
wait(1)
local voo = c.RightUpperArm:FindFirstChildWhichIsA("Motor6D")
local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
a0.CFrame = voo.C0
a1.CFrame = voo.C1
a0.Parent = voo.Part0
a1.Parent = voo.Part1
local b = Instance.new("HingeConstraint")
b.Attachment0 = a0
b.Attachment1 = a1
b.Parent = voo.Part0
local c = Instance.new("BallSocketConstraint")
c.Attachment0 = a0
c.Attachment1 = a1
c.Parent = voo.Part0
voo:Destroy()
wait(1)
---b.LimitsEnabled = false
----b.MaxAngle = 0
c.Name = "joint1"
b.Name = "Hinge1"
b.LowerAngle = 0
b.UpperAngle = 0
b.LimitsEnabled = true
-- b.Enabled = false
--a0.Name = "Attachment00"
--a0.Orientation = Vector3.new(0,-180,-90)
--p.PlayerGui.ScreenGui.Grab.MouseButton1Click:Connect(function()
-- end)
--local gyro = Instance.new("BodyGyro",c.RightUpperArm)
-- gyro.CFrame= workspace.hmmm.CFrame
-- gyro.MaxTorque = Vector3.new(100000,0,0)
end)
end)
actual grabscript:
wait(1)
local ready = false
local stage2 = false
local button = script.Parent
local char = script.Parent.Parent.Parent.Parent.Character
local hand = char.RightHand
local arm = char.RightUpperArm
local atch = char.UpperTorso:WaitForChild("Hinge1")
local UserInputService = game:GetService("UserInputService")
local function Grab()
print(ready)
if ready == false and stage2 == false then
ready = true
atch.LimitsEnabled = true
atch.Enabled = true
atch.LowerAngle = 90
atch.UpperAngle = 90
elseif ready == true then
ready = false
-- Lower hand
atch.LimitsEnabled = true
atch.Enabled = true
atch.LowerAngle = 0
atch.UpperAngle = 0
elseif stage2 == true then
stage2 = false
-- Delete weld
atch.LimitsEnabled = true
atch.Enabled = true
atch.LowerAngle = 0
atch.UpperAngle = 0
hand.WeldConstraint:Destroy()
end
end
local remote = game.ReplicatedStorage.Remote.RightGrab
remote.OnServerEvent:Connect(function(player)
Grab()
end)
button.MouseButton1Click:Connect(function()
Grab()
end)
hand.Touched:Connect(function(hit)
if ready == true then
local IFFY1 = hit:FindFirstAncestorWhichIsA("Model")
local IFFY2 = IFFY1:FindFirstChild("Humanoid")
if not IFFY2 then
local weld = Instance.new('WeldConstraint', hand)
weld.Part0 = hand
weld.Part1 = hit
atch.LimitsEnabled = false
atch.Enabled = false
ready = false
stage2 = true
end
end
end)
localscript:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Right = ReplicatedStorage.Remote:WaitForChild("RightGrab")
local Left = ReplicatedStorage.Remote:WaitForChild("LeftGrab")
local function OnKeyPress(input)
if input.KeyCode == Enum.KeyCode.E then
Right:FireServer()
elseif input.KeyCode == Enum.KeyCode.Q then
Left:FireServer()
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then -- Right trigger (RT)
Right:FireServer()
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then -- Left trigger (LT)
Left:FireServer()
end
end
local function OnKeyRelease(input)
if input.KeyCode == Enum.KeyCode.E then
-- Release logic for E key
Right:FireServer() -- Fire the grab function for the released button
elseif input.KeyCode == Enum.KeyCode.Q then
-- Release logic for Q key
Left:FireServer() -- Fire the grab function for the released button
elseif input.KeyCode == Enum.KeyCode.ButtonR2 then -- Right trigger (RT)
-- Release logic for Right trigger
Right:FireServer() -- Fire the grab function for the released button
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then -- Left trigger (LT)
-- Release logic for Left trigger
Left:FireServer() -- Fire the grab function for the released button
end
end
UserInputService.InputBegan:Connect(OnKeyPress)
UserInputService.InputEnded:Connect(OnKeyRelease)