Arrest script problem

Hello, I am a new scripter.i am making a script about an arrest tool. But I want when someone has been arrested. Then will have this Animation:

I don’t know how to make, I try to search that but nothing. ;(

My Tool:

55167233gf's Place Number_ 23 - Roblox Studio 15_9_2020 13_23_56

My script: (ToolScript)

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local reloadTime = 2
local range = 10
local rE = script.Parent:WaitForChild("Arrest")

tool.Enabled = true

tool.Equipped:connect(function(mouse)
	print("Tool equipped!")
 
	mouse.Button1Down:connect(function()
		print("Mouse pressed!")
		
		if not tool.Enabled then
			return
		end

		tool.Enabled = false
		
		local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * range)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
		
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				local tarplr = humanoid.Parent
				local stats = game.Players[tarplr.Name]:FindFirstChild("CanArrest")
				if stats.Value == true then
					game.Players[tarplr.Name].Team = game.Teams.Prisoner
					print("Arresting")
					rE:FireServer(tarplr)
				else
					print("Player cant arrest")
				end
			end
		end
		
		wait(reloadTime)
						
		tool.Enabled = true

	end)
end)

My script:(REArrest)

script.Parent:WaitForChild("Arrest").OnServerEvent:Connect(function(plr, tarplr)
	if game.Players[tarplr.Name].Team ~= game.Teams.Police then
		print(plr.Name.." is attempting to arrest")
		print(plr.Name.." is attempting to arrest "..tarplr.Name)
		game:GetService("Players")[tarplr.Name].Character.Humanoid.WalkSpeed = 0
		game.Players[tarplr.Name].PlayerGui.Shift.Disabled = true
		wait(15)
		game:GetService("Players")[tarplr.Name].Character.Humanoid.WalkSpeed = 16
		game.Players[tarplr.Name].PlayerGui.Shift.Disabled = false
		game:GetService("Players")[tarplr.Name].Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.TeleportPart.Position)
		--change the above part to where you want the person teleported too
	end
end)

I hope someone can help me :slight_smile:

1 Like

Assuming you already have the animation created, you can load the animation into the desired Humanoid with LoadAnimation(), and play it with :Play().

Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://" .. AssetId --replace AssetId with the asset ID of your animation

AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
1 Like

Like this?

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid" .. 5690664285 
	
local AnimationTrack = game.Workspace[tarplr.Name].Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()

Sorry I don’t know why not working

when I arrest another player, the player not playing the animation

The code @ExcessEnergy posted should work. Just make sure to use rbxassetid:// instead of rbxassetid.

Sorry about the typo. I somehow overlooked it being on a small mobile screen at the moment. It has been fixed.

Yes, I changed the rbxassetid://
But still not working

It looks like your game is using R6. Be absolutely sure your animation can be loaded into an R6 rig via the animation editor plugin before trying to use it in-game or else it won’t load and won’t error.

1 Like

Are you getting any errors or warnings in the output? Are you sure the animation ID you are using is valid, and is compliant with your rig?

Also, can you update your original post with the most recent version of your code, so we can recheck it?

@ExcessEnergy I am not getting any errors

Animation.AnimationId = “rbxassetid” … 5690664285 should be Animation.AnimationId = “rbxassetid://5690664285” not with the …

ok so no extra dots just put the exact id

You can do it either way. “…” is just a way to concatenate the two values together into one, and it allows you to implement a variable for the asset ID instead of using the entire string at once.

um you can’t do it either way unless 5690664285 is a variable and yes … is a way to concentrate two DIFFERENT values. you can put 2 strings but it is so much more efficient to use 1 string

Im glad to here that the animation is working for you @55167233gf

my example would be

local number = Instance.new("IntVal")
number.Value = 1

print("asdfasdf" .. number)

@ExcessEnergy
this would print asdfasdf1

I need upload a video but i cant upload :frowning:

you can upload the video by going to the upload sign right next to the bulleted list on the top of your post. Then you can choose your file.

The test video

1 Like

I’m glad you found your solution! please if you could give me credit for that as for that is logged in the forum.

1 Like