Check if player is near humanoid if he is, and presses key then do something

  1. When a player gets close to another player and presses a key it will do a script like welding.

  2. Old script does not work anymore.

  3. Tried troubleshooting old script

Server Script:


local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("remotes")
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		repeat wait()until char.Head
		local newValue = Instance.new("BoolValue", char)
		newValue.Name = "HandcuffValue"
		newValue.Value = false
		char.Parent = game.Workspace:WaitForChild("Players")

	end)
end)

	
local Player = game.Players.LocalPlayer
local Animation = game.Workspace.Animation
local Players = game:GetService("Players")





















folder.handcuff.OnServerEvent:Connect(function(player,p)

	p.HandcuffValue.Value = true
	p.Humanoid.WalkSpeed = 8


	local Weld1 = Instance.new("Weld")
	Weld1.Name = "Tool_Weld2"
	Weld1.Part0 = p.Torso
	Weld1.Part1 = p['Right Arm']
	Weld1.Parent = p.Torso
	Weld1.C1 = CFrame.new(-1 * .65, -.35, -.35) * CFrame.fromEulerAnglesXYZ(math.rad(17.5), math.rad(0), math.rad(-1 * -40))
	local Weld2 = Instance.new("Weld")
	Weld2.Name = "Tool_Weld3"
	Weld2.Part0 = p.Torso
	Weld2.Part1 = p['Left Arm']
	Weld2.Parent = p.Torso
	Weld2.C1 = CFrame.new(1 * .65, -.35, -.35) * CFrame.fromEulerAnglesXYZ(math.rad(17.5), math.rad(0), math.rad(1 * -40))

	
end)


	

	

	


folder.uncuff.OnServerEvent:Connect(function(player,p)

	p.HandcuffValue.Value = false
	p.Humanoid.WalkSpeed = 16


	p.Torso.Tool_Weld2:Destroy()
	p.Torso.Tool_Weld3:Destroy()
	end)



			
	
		

		



Local Script:

local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("remotes")
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local players = game.Workspace:WaitForChild("Players")
local character = players:WaitForChild(player.Name)
character.Parent = game.Workspace

uis.InputBegan:Connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.G and gameProcessed == false then
		for i,p in pairs(players:GetChildren()) do
			if (character.HumanoidRootPart.Position).magnitude <= 10 then
				if p.GrabValue.Value == false then
					print("fired remote")
					folder.grab:FireServer(p)
				else
					folder.ungrab:FireServer(p)
				end
			end
		end
	end
end)