Hi,
I am trying to create some handcuffs for my game. They are designed so that if a person has a certain amount of bounty, they can be arrested. It is supposed to change the person’s team to Jailed and respawn them in prison.
My issue is that when I click on a player with the handcuffs equipped, the handcuffs do not do anything and no errors appear in the output.
I have tried looking at existing topics on the DevForums and on Youtube, but have been unable to find anything that can help.
Here is the script for the handcuffs (it is a local script, located inside a tool in the StarterPack).
tool = script.Parent
handle = tool:WaitForChild("Handle")
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:connect(function()
if mouse then
if (script.Parent.Parent.Head.Position == mouse.Target.Parent.Parent.Head.Position).magnitude <= 10 then
if mouse.Target.Parent:isA('Accessory') then
local char = mouse.Target.Parent.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if plr.leaderstats.Bounty.Value <= 10 then
plr.TeamColor = BrickColor.new('Medium stone grey')
plr.LoadCharacter()
end
end
end
end
end)
end)
If anyone could help it would be much appreciated!
It’s because your doing it in a local and not server script like changing the bounty and tampering with other characters other than yourself, affecting the server with local instead of using a remote event or function because of filtering enabled. So I think that’s it.
also you could just put char as the mouse.Target.Parent and then do the rest still using a remote event and you could just use the tool.Activated event instead to save more time and make the mouse a variable. (still using a remote event or function). and there could be more bugs but I can’t see right now though.
As @Miniblame has mentioned, you should use a remote event or remote function (depending on your desire, but I think in this case Remote Event should be used as there is no info to be returned).
Secondly, there is an event called activated associated with Tool to make work easier.
tool.Activated:Connect(function()
end)
and I would also suggest that instead of doing
script.Parent.Parent.Head.Position - mouse.Target.Parent.Parent.Head.Position
you store your player in a variable and use this DistanceFromCharacter function which will
return the distance between your character’s head and the given Vector3 point.
so you can phrase it like this:
if player:DistanceFromCharacter(mouse.Target.Parent.Position) < 10 then