Handcuffs thinks the current officer is the previous one

  1. What do you want to achieve? I want to not have the tool think the current officer is the previous one

  2. What is the issue? This happens:
    https://www.youtube.com/watch?v=nuiiVWdxBns

  3. 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).

There is an ungrab method

function Handcuffs:Ungrab()
	if self.Subject then
		self.Subject.Character.HumanoidRootPart.Anchored = false
		self.Grabbing = false
		self.Subject = nil
	end
end

When/ What fires these methods? Is it in a script or a local script, UIS, keyDown, etc?

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()

I’d recommend using UIS’ inputBegan and inputEnded, it would just seem to make life a lot easier for you and may solve the issue.

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.

1 Like

Thank you, that was indeed the problem :slight_smile:

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.

1 Like