Advertisement
LightningTNT

Handcuffs script, with distance checking

Jul 1st, 2021
2,751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.19 KB | None | 0 0
  1. local event = game:GetService("ReplicatedStorage").Arrest
  2. local distance = 10
  3.  
  4.  
  5. event.OnServerEvent:Connect(function(policeman, arrested) -- when the event gets fired, the server will do the following commands:
  6.     if(arrested.Team ~= game.Teams.Police) then --if the player's team is not police then
  7.         if(policeman:DistanceFromCharacter(arrested.Character:WaitForChild("HumanoidRootPart").Position) > distance) then
  8.             return nil
  9.         end
  10.         if(arrested.BadArea.Value == true and arrested.Team == game.Teams.Prisoners) then --If he is a prisoner in the area he is not allowed to.
  11.             arrested.Character:WaitForChild("Humanoid").WalkSpeed = 0 --Set the arrested person walk speed to 0
  12.             arrested.Character:WaitForChild("Humanoid").JumpPower = 0 --Set the arrested person jump power to 0
  13.             local clone1 = game:GetService("ServerStorage").Handcuff:Clone() --Clone the handcuff cylinder we made
  14.             local clone2 = game:GetService("ServerStorage").Handcuff:Clone() --Clone the handcuff cylinder we made again
  15.             clone1.Parent = arrested.Character --Set it's parent to the character
  16.             clone2.Parent = arrested.Character --Set it's parent to the character
  17.             local motor = Instance.new("Motor6D", arrested.Character) --Create a new motor 6d and set it's parent to the character
  18.             local motor2 = Instance.new("Motor6D", arrested.Character) --Create a new motor 6d again and set it's parent to the character
  19.             motor.Part0 = arrested.Character.LeftHand --The part0 of the motor 6d is the leftHand
  20.             motor.Part1 = clone1 --The part0 of the motor 6d is the handcuff clone 1
  21.             motor2.Part0 = arrested.Character.RightHand --The part0 of the motor 6d 2 is the rightHand
  22.             motor2.Part1 = clone2 --The part0 of the motor 6d 3 is the handcuff clone 2
  23.             local chain = Instance.new("RopeConstraint", arrested.Character) --Create a new rope constraint inside the character
  24.             local atta1 = Instance.new("Attachment", clone1) --Create a new attachment inside the clone1
  25.             local atta2 = Instance.new("Attachment", clone2)--Create a new attachment inside the clone2
  26.             chain.Length = 1 --Set the rope's length to 1
  27.             chain.Thickness = 0.2 --Set the rope's thickness to 0.2
  28.             chain.Attachment0 = atta1 --The rope's attachment 1 is the atta1 attachment
  29.             chain.Attachment1 = atta2 --The rope's attachment 2 is the atta2 attachment
  30.             chain.Color = BrickColor.new("Light stone grey") --Set the rope color to gray
  31.             chain.Visible = true --Make it visible
  32.             arrested.BadArea.Value = false
  33.             game.ReplicatedStorage.ArrestAnim:FireClient(arrested) --Fire the client fromthe event we created
  34.             wait(6) --Cooldown between arresting and playing animation
  35.             arrested.Team = game.Teams.Prisoners --change the team of the player to prisoner
  36.             arrested:LoadCharacter() --respawn him
  37.         elseif(arrested.Team == game.Teams.Criminals) then  --If he is a criminal, the area he is inside does not matter, he will get arrested
  38.             arrested.Character:WaitForChild("Humanoid").WalkSpeed = 0 --Set the arrested person walk speed to 0
  39.             arrested.Character:WaitForChild("Humanoid").JumpPower = 0 --Set the arrested person jump power to 0
  40.             local clone1 = game:GetService("ServerStorage").Handcuff:Clone() --Clone the handcuff cylinder we made
  41.             local clone2 = game:GetService("ServerStorage").Handcuff:Clone() --Clone the handcuff cylinder we made again
  42.             clone1.Parent = arrested.Character --Set it's parent to the character
  43.             clone2.Parent = arrested.Character --Set it's parent to the character
  44.             local motor = Instance.new("Motor6D", arrested.Character) --Create a new motor 6d and set it's parent to the character
  45.             local motor2 = Instance.new("Motor6D", arrested.Character) --Create a new motor 6d again and set it's parent to the character
  46.             motor.Part0 = arrested.Character.LeftHand --The part0 of the motor 6d is the leftHand
  47.             motor.Part1 = clone1 --The part0 of the motor 6d is the handcuff clone 1
  48.             motor2.Part0 = arrested.Character.RightHand --The part0 of the motor 6d 2 is the rightHand
  49.             motor2.Part1 = clone2 --The part0 of the motor 6d 3 is the handcuff clone 2
  50.             local chain = Instance.new("RopeConstraint", arrested.Character) --Create a new rope constraint inside the character
  51.             local atta1 = Instance.new("Attachment", clone1) --Create a new attachment inside teh clone1
  52.             local atta2 = Instance.new("Attachment", clone2)--Create a new attachment inside teh clone2
  53.             chain.Length = 1 --Set the rope's length to 1
  54.             chain.Thickness = 0.2 --Set the rope's thickness to 0.2
  55.             chain.Attachment0 = atta1 --The rope's attachment 1 is the atta1 attachment
  56.             chain.Attachment1 = atta2 --The rope's attachment 2 is the atta2 attachment
  57.             chain.Color = BrickColor.new("Light stone grey") --Set the rope color to gray
  58.             chain.Visible = true --Make it visible
  59.             game.ReplicatedStorage.ArrestAnim:FireClient(arrested) --Fire the client fromthe event we created
  60.             arrested.BadArea.Value = false
  61.             wait(6) --Cooldown between arresting and playing animation
  62.             arrested.Team = game.Teams.Prisoners --change the team of the player to prisoner
  63.             arrested:LoadCharacter() --respawn him
  64.         end
  65.     end
  66. end)
  67.  
  68. --the first thing we get from the event is the client that fired the event, the secod thing, is what we passed from there, which is the arrested player
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement