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

How do I make my handcuffs work only if the player is a criminal?

Asked by 6 years ago
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Team == Criminal
hit.Parent:MoveTo(game.Workspace.Part.Position)
end
end)    

The script works if I don't put if hit.Team == Criminal, but it will work if the player is in a team like Police.

How do I make it so it only can arrest Criminals?

2 answers

Log in to vote
0
Answered by 6 years ago

In your script, hit refers to the literal brick that touches the handle, for example a left arm or a right leg. Team is a property of the player class, so you will need to edit line 2 like so:

if game.Players:GetPlayerFromCharacter(hit.Parent).Team = game:GetService("Teams"):FindFirstChild("Criminal") then

Of course, I'm assuming Criminal is the name of your team. If any of these functions sound new to you, look them up on the Roblox wiki. Hope this helps

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Since you are using the Touched function, the parameter hit you defined will be something the handcuffs collide with, not the targeted player. You would have to find the player through the character. You also forgot another end

script.Parent.Handle.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) --gets player from character
        if player then --checks if the player exists
            if player.Team == game:GetService("Teams"):FindFirstChild("Criminal") then
                hit.Parent:MoveTo(game.Workspace.Part.Position)
            end
        end
    end
end)    

0
When I use this script the player teleports to the jail then they teleport back to the handcuffs Gameplay28 139 — 6y

Answer this question