Do not works. Tool

image
image

Part = script.Parent 
local player = game.Players:FindFirstChild(hit.Parent.Name)
local debounce = false
------------------------------------
modelname="Prisoners" -- Put the EXACT name of the team here
------------------------------------
 
function onTouched(hit) 
        local human = hit.Parent:FindFirstChild("Humanoid") 
        if (human ~= nil ) then
                if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then
		if debounce == false then
			debounce = true
			player.leaderstats.Money.Value = player.leaderstats.Money.Value + 100	
			human.Parent.HumanoidRootPart.Anchored = true
			wait(5)
			human.Parent.HumanoidRootPart.Anchored = false
			human.Parent:MoveTo(workspace.Prison.Position)
			wait(10)
			debounce = false
			end
                end
 
        end 
end 
 
connection = Part.Touched:connect(onTouched)

Idk why it do not works. Pls help

local player = game.Players:FindFirstChild(hit.Parent.Name)

hit is undefined here, did you mean to put it in the onTouched function?

Not. I need someone who holds this item

Then change

local player = game.Players:FindFirstChild(hit.Parent.Name)

To

local player = game.Players:FindFirstChild(Part.Parent.Parent.Name)

No, I need the one who holds this object in his hands, and not the one to whom he touches

That’s what my change does, Part is your variable that contains the part for the handcuffs, it gets its parent, the tool, and then it gets its parent, the character who has the handcuffs tool, and then it gets the name of who has the handcuffs tool find finds the player from there

No. I tested it and it doesn’t work(

Money is given to the one to whom it touched.

Huh? What is your entire code as of now? Maybe try this?

local Part = script.Parent 
local player = game.Players:FindFirstChild(Part.Parent.Parent.Name)
local debounce = false
------------------------------------
modelname="Prisoners" -- Put the EXACT name of the team here
------------------------------------
 
function onTouched(hit) 
	local human = hit.Parent:FindFirstChild("Humanoid") 
	if (human ~= nil ) then
		if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then
			if debounce == false then
				debounce = true
				player.leaderstats.Money.Value += 100	
				human.Parent.HumanoidRootPart.Anchored = true
				wait(5)
				human.Parent.HumanoidRootPart.Anchored = false
				human.Parent:MoveTo(workspace.Prison.Position)
				wait(10)
				debounce = false
			end
		end

	end 
end 
 
connection = Part.Touched:connect(onTouched)
Part = script.Parent 
local debounce = false
local player = game.Players:FindFirstChild(Part.Parent.Parent.Name)

------------------------------------
modelname="Criminals" -- Put the EXACT name of the team here
------------------------------------
 
function onTouched(hit) 
        local human = hit.Parent:FindFirstChild("Humanoid") 
        if (human ~= nil ) then
		if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then
			if debounce == false then
				debounce = true
				player.leaderstats.Money.Value += 100
				local name = hit.Parent.Name
				local player = game.Players:FindFirstChild(name)
				player.TeamColor = BrickColor.new("Deep orange")
				human.Health = 0
				wait(10)
				debounce = false
			end
        end
        end 
end 
 
connection = Part.Touched:connect(onTouched)

Question, did you make this tool or is it a free model?

good question bro is a free model?

no, I made it. Only mesh I took from free model

1 Like

Yeah because you seem to be using some inefficient way to handle a cuff tool, I don’t really recommend using .Touched, you’d obviously face a lot of errors, It’s better if you use Input management for a cuff tool

I would love to, but I don’t know how

The following is better and efficient:

UserInputService [client] you can use it to detect input like MouseClick then decide what to do with that
Remote Functions and Events [server <-> client] so you can link and make a communication between Client <-> Server

Then on the server code you would just handle properties, data, instances, teaming.etc
If you have any trouble understanding this then you can look up tutorials

Can’t you use the MouseDown event of the player’s mouse that Tool.Equipped gives so when you click it it’ll arrest the first person touching the handcuffs?

help me to fix the second line.
local player = game.Players:FindFirstChild(Part.Parent.Parent.Name)

I need to give money not to the one whom I touched, but to the one who is holding the object

Can’t you do something like this?

local Part = script.Parent 
local debounce = false
------------------------------------
modelname="Prisoners" -- Put the EXACT name of the team here
------------------------------------
 
function onTouched(hit) 
	local human = hit.Parent:FindFirstChild("Humanoid") 
	local player = game.Players:GetPlayerFromCharacter(Part.Parent.Parent)
	local prisonerPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
	if debounce or not player or not human or not prisonerPlayer then return end
	
	if prisonerPlayer.TeamColor == game.Teams[modelname].TeamColor then
		debounce = true
		player.leaderstats.Money.Value += 100	
		human.Parent.HumanoidRootPart.Anchored = true
		wait(5)
		human.Parent.HumanoidRootPart.Anchored = false
		human.Parent:MoveTo(workspace.Prison.Position)
		wait(10)
		debounce = false
	end
end 
 
connection = Part.Touched:connect(onTouched)