Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

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)    

1 comment

0

When I use this script the player teleports to the jail then they teleport back to the handcuffs

This discussion is preserved as it was. New answers, comments, and votes are closed.