What solutions have you tried so far? Redefining Officer every time Grab() is fired
Relevant method of class:
function Handcuffs:Grab(Subject)
if not Subject:IsA("Player") then return end
self.Officer = self.Tool:FindFirstAncestorWhichIsA("Player") or Players:GetPlayerFromCharacter(self.Tool.Parent)
self.Subject = Subject
FastSpawn(function()
self.Subject.Character.HumanoidRootPart.Anchored = true
self.Grabbing = true
RunService.Heartbeat:Connect(function()
if not self.Grabbing then return end
Subject.Character.HumanoidRootPart.CFrame = self.Officer.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(2.5,0,-2.5))
end)
return
end)
end
I believe the issue here is the officer is never actually let down/forgotten, meaning when you update the position the officer tries to get in front of the other officer, both overlapping eachother into oblivion.
What you should also do is either remove or make self.Grabbing = false, as right now it’s never ending, meaning the grabbing is always on-going. (unless there’s another function that makes it false).
function Handcuffs:Ungrab()
if self.Subject then
self.Subject.Character.HumanoidRootPart.Anchored = false
self.Grabbing = false
self.Subject = nil
end
end
A LocalScript in the tool listens to Button1Down and Fires a RemoteEvent to a Server Script in the tool, If the current subject isn’t the same as the one from Mouse.Target then it will call Grab() else it will call Ungrab()
The Heartbeat event connection is never disconnected, so it’s still changing the CFrame of Subject (not self.Subject).
You could make a variable that references the connection which when :Ungrab() is called, the Event connection is disconnected and no longer runs code every time Heartbeat is fired. return or break won’t break the Event connection, either.
On a separate note, I would recommend that you mark the last post I made as the “Solution” for other developers who are potentially struggling with this problem.