Why does this cuff the user with the tool?

Hi, I’m currently making a handcuffing system for a package that I will release. I’m having an issue where when the player clicks on someone, the player that clicks gets cuffed, instead of the person that they clicked. I can’t seem to figure out why this happens.

Client Script

local events = rs.HandcuffsEvents
local grabEvent = events.PlayerGrabbed

local tool = script.Parent
local plr = game.Players.LocalPlayer
local animation = script.Parent:WaitForChild("DetainedAnimation")
local mouse = plr:GetMouse()
local char = plr.Character
local hum = char.Humanoid
local animator = hum:WaitForChild("Animator")

local animClone =  animation:Clone()


tool.Equipped:Connect(function(mouse)
	tool.Activated:Connect(function()
		if mouse.Target.Parent then
			if mouse.Target.Parent:IsA("Accessory") then
				print(mouse.Target.Parent.Parent)
				local plrTarget = mouse.Target.Parent.Parent
				grabEvent:FireServer(mouse.Target)
			elseif mouse.Target.Parent:IsA("Model") then
				print(mouse.Target.Parent)
				local plrTarget = mouse.Target.Parent
				grabEvent:FireServer(mouse.Target) 
			else end
		end
	end)
end)

Server Script

local events = rs.HandcuffsEvents
local grabEvent = events.PlayerGrabbed

grabEvent.OnServerEvent:Connect(function(mouseTarget)
	local animClone = script.Parent.DetainedAnimation:Clone()
	animClone.Parent = mouseTarget
	local animTrack = mouseTarget.Character.Humanoid.Animator:LoadAnimation(animClone)
	animTrack:Play()
	task.wait(.24)
	animTrack:AdjustSpeed(0)
end)

Any help is much appreciated! Thank you.

mouseTarget here is actually where the player is automatically sent to the server when an event is fired so it should look like

grabEvent.OnServerEvent:Connect(function(Player, mouseTarget)

2 Likes

Exactly what @Nyonic said.

The reason this happens is cause when you fire an event it gives you the player value first, then the other values.

This is how you would get the value of the player who fired the event.
This only works when sending an event to the server, other wise you have to send the player value manually
(I mean if your sending a client event you would already have the player so)

also make sure to mark @Nyonic as the solution

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.