Hi,
Im trying to make an arrest system.
As one option, you should be able to move the arrested player to you, so he is following you. I tried that using :MoveTo but it’s not working. There are no errors and the player just stands still.
Here’s the part where I think the error is:
for i, v in pairs(target) do
moving = true
while moving == true do
wait(0.1)
v.Humanoid:MoveTo(Vector3.new(plr.Character.HumanoidRootPart.Position))
v.Humanoid.MoveToFinished:Connect(function()
moving = false
end)
end
end
The full script:
local rep = game:GetService("ReplicatedStorage"):WaitForChild("ArrestEvent")
local cuffedPlayers = {}
local UnloadedAnim = script.Parent.Animation
onGoing = false
moving = false
rep.OnServerEvent:Connect(function(plr, target, method)
if method == 1 then
local hum = target:FindFirstChild("Humanoid")
local Anim = hum:LoadAnimation(UnloadedAnim)
if table.find(cuffedPlayers, target.Name) then
table.remove(cuffedPlayers, table.find(cuffedPlayers, target.Name))
rep:FireClient(plr, target)
--local controls = require(target.LocalPlayer.PlayerScripts:FindFirstChild("PlayerModule"):GetControls())
--controls:Enable()
Anim:AdjustSpeed(0.9)
else
if onGoing == false then
onGoing = true
table.insert(cuffedPlayers, target.Name)
Anim:Play()
wait(0.8)
Anim:AdjustSpeed(0)
--local controls = require(target.LocalPlayer.PlayerScripts:FindFirstChild("PlayerModule"):GetControls())
--controls:Disable()
onGoing = false
end
end
elseif method == 2 then
for i, v in pairs(target) do
moving = true
while moving == true do
wait(0.1)
v.Humanoid.MoveToFinished:Connect(function()
moving = false
end)
v.Humanoid:MoveTo(Vector3.new(plr.Character.HumanoidRootPart.Position))
end
end
end
end)
The local script:
wait(1)
local plr = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local rep = game:GetService("ReplicatedStorage"):WaitForChild("ArrestEvent")
local UI = plr.PlayerGui:FindFirstChild("ArrestUI")
local BodyParts = {"Head", "Left Arm", "Right Arm", "Right Leg", "Left Leg", "HumanoidRootPart", "Torso", }
local cuffed = {}
script.Parent.Activated:Connect(function()
if mouse.Target then
if table.find(BodyParts, mouse.Target.Name) then
local target = mouse.Target.Parent
table.insert(cuffed, target)
rep:FireServer(target, 1)
end
end
end)
rep.OnClientEvent:Connect(function(target)
table.remove(cuffed, table.find(cuffed, target))
end)
script.Parent.Equipped:Connect(function()
UI.Frame.Visible = true
end)
script.Parent.Unequipped:Connect(function()
UI.Frame.Visible = false
end)
UI.Frame.Follow.MouseButton1Click:Connect(function()
rep
for i, v in pairs(target) do
moving = true
while moving == true do
wait(0.1)
v.Humanoid.MoveToFinished:Connect(function()
moving = false
end)
v.Humanoid:MoveTo(Vector3.new(plr.Character.HumanoidRootPart.Position))
end
end
So this is really weird what happens now…
So first time trying it, the cuffedMan moves just a bit and stops and then nothing happens. If I try it with the other person, it works but then not a second time. I provided now also the full script, cause maybe the problem is there.
Reason for the loop is, because target is a table with all cuffedPlayers in it and all players who are cuffed by this Person should move to him so thats why.
for i, v in pairs(target) do
target.HumanoidRootPart.CFrame = CFrame.new(plr.Character.HumanoidRootPart.CFrame.X + 10, plr.Character.HumanoidRootPart.CFrame.Y, plr.Character.HumanoidRootPart.CFrame.Z)
end
I get this error:
Players.Faustollol.Backpack.Arrest.Script:44: attempt to index nil with ‘CFrame’
did you try the solution i sent because you aren’t getting errors which means the loop isnt firing. also groups are instances so using pairs is bad, use ipairs
put prints everywhere on the client where it sends the data and on the server and tell me if it sends you anything and what it sends and ill try to help from there
Are you calling MoveTo() on the humanoid so it follows you?
-- Get the Humanoid object of the follower
local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")
local function Follow()
while true do
-- Check if the target player has a character
if targetPlayer.Character then
local targetPosition = targetPlayer.Character:GetPrimaryPartCFrame().Position
targetHumanoid:MoveTo(targetPosition) -- Use MoveTo to move towards the target
end
wait(0.1) -- Adjust the update frequency as needed
end
end
If you want to move the model itself, you can use :SetPrimaryPartCFrame() (I believe this is going to be depreciated) or :PivotTo() instead.