How do I make this script work to undetain a player?
Hi! So the script I'm linking below doesn't work. t's meant to undetain a player when they unequip a tool except it doesn't work. No errors
01 | local players = game:GetService( "Players" ) |
02 | local player = players.LocalPlayer |
03 | local mouse = player:GetMouse() |
04 | local targetplayer = script.Parent.Parent.PlayerGui:WaitForChild( "ArrestDetails" , 5 ).Frame.TextLabel.name.Value |
06 | mouse.Button 1 Down:Connect( function () |
07 | if mouse.Target.Parent:FindFirstChild( "Humanoid" ) then |
08 | if game.Workspace [ player.Name ] :FindFirstChild( "Arrest" ) then |
09 | local targettedplayer = mouse.Target.Parent.Name |
10 | print (targettedplayer) |
11 | player.PlayerGui.ArrestDetails.Frame.TextLabel.Text = "Target Player: " ..targettedplayer |
12 | player.PlayerGui.ArrestDetails.Frame.TextLabel.name.Value = targettedplayer |
13 | local userId = player.UserId |
14 | local thumbType = Enum.ThumbnailType.HeadShot |
15 | local thumbSize = Enum.ThumbnailSize.Size 420 x 420 |
16 | local content, isReady = players:GetUserThumbnailAsync(userId, thumbType, thumbSize) |
17 | local imageLabel = player.PlayerGui.ArrestDetails.Frame.Character |
18 | imageLabel.Image = content |
19 | player.PlayerGui.ArrestDetails.Frame.MainGroupRank.Text = "Main Group Rank: " ..game.Players [ targettedplayer ] :GetRoleInGroup( 5552081 ) |
20 | game.ReplicatedStorage.ArrestedAnimation:FireServer(targettedplayer) |
21 | player.PlayerGui.ArrestDetails.Frame.Visible = true |
23 | if mouse.Target~ = nil then |
24 | print (mouse.Target:GetFullName()) |
26 | _,p = pcall ( function () return game.Players [ mouse.Target.Parent.Name ] end ) |
28 | print (mouse.Target.Parent.Name) |
31 | coroutine.wrap( function () |
33 | while p = = c do wait() pcall ( function () |
34 | p.Character.Torso.Anchored,p.Character.Torso.CFrame = false ,game.Players.LocalPlayer.Character.Torso.CFrame*CFrame.new( 0 , 0 ,- 2.5 ) |
35 | game.ReplicatedStorage.ok.Event():Connect( function (c,p) |
36 | print ( "undetain event fired" ) |
41 | print ( 'END OF DETAIN LOOP' ) |
42 | pcall ( function () c.Character.Torso.Anchored = false end ) |
69 | script.Parent.Arrest.Unequipped:Connect( function () |
71 | script.Parent.Parent.PlayerGui.ArrestDetails.Frame.Visible = false |
72 | local targetplayer = script.Parent.Parent.PlayerGui.ArrestDetails.Frame.TextLabel.name.Value |
73 | game.ReplicatedStorage.ArrestedAnimationOff:FireServer(targetplayer) |
79 | game.Players [ targetplayer ] .Character.Torso.Anchored,game.Players [ targetplayer ] .Character.Torso.CFrame = true ,game.Players.LocalPlayer.Character.Torso.CFrame*CFrame.new( 0 , 0 ,- 2.5 ) |
80 | game.Players [ targetplayer ] .Character.Torso.CFrame = game.Players.LocalPlayer.Character.Torso.CFrame*CFrame.new( 0 , 0 ,- 2.5 ) |
81 | game.Players [ targetplayer ] .Character.Torso.Anchored = true |
82 | game.ReplicatedStorage.ok:Fire() |