Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to Detain a player and store that player's UserId?

Asked by 4 years ago

I'm basically trying to create an arrest system where I can detain someone, drag them over to the vehicle backdoor, and use a keybind to either A.) place them in the car for transport or B.) teleport them straight to the jail.

I already have the detain from a freemodel script, I'm just having trouble storing the detained persons UserId.

local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local TargetTorso = nil
local Using       = false


function CheckForTargetTorso(part)
    if part.Parent:IsA'Model' and part.Parent:FindFirstChildOfClass'Humanoid' then
        local char = part.Parent
        local torso
        if char:FindFirstChild'Torso' then
            torso = char.Torso
        elseif char:FindFirstChild'UpperTorso' then
            torso = char.UpperTorso
        end
        return char, torso
    end
end



function CheckForTorso(player)
    local Char = player.Character
    if Char:FindFirstChild'Torso' then
        return Char.Torso
    else 
        return Char.UpperTorso
    end
end


RemoteEvent.OnServerEvent:Connect(function(player, state, part)

    if state == 'Cuff' then
        local target      = nil
        local playerTorso = nil

        target, TargetTorso = CheckForTargetTorso(part)
        playerTorso = CheckForTorso(player)

        if target then
            Using = true
            RemoteEvent:FireClient(player, 'Use')
            spawn(function()
                if Using then
                    TargetTorso.Anchored = true         
                end             
                while Using and wait() do           
                    TargetTorso.CFrame = playerTorso.CFrame * CFrame.new( 0, 0, -5 )
                end             

            end)            

        end

    elseif state == 'UnCuff'then    
        Using = false       
        TargetTorso.Anchored = false
        wait()
    end

end)
0
Id say if you get there character then use the API that gets the player from the character would type an anwser but sadly I don't have time deth836231 142 — 4y
0
To retrieve the UserId, you will most likely want to check if the target is indeed a player (it can be an NPC). Do this using the GetPlayerFromCharacter function of game.Players. From then, you can simply retrieve the id from the UserId property. My question is—where do you want to store the UserId? I recommend DataStoreService. VinnyTheButcher 278 — 4y

Answer this question