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

Where have I gone wrong leading to me getting a userdata value error in this script?

While clicking on myself to test a tool I've made, I've been getting 20:36:34.831 - Players.Player1.Backpack.Arrest Tool.LocalScript:10: attempt to call field 'Button1Down' (a userdata value). I checked SH and found someone getting the same error, but they forgot a comma. I'm pretty sure I've written everything correctly, but apparently not. Thank you for any and all help!

tool = script.Parent
local canArrest = false
local mouse = game.Players.LocalPlayer:GetMouse()

tool.Equipped:connect(function()
	canArrest = true
	if canArrest == true then
		local target = mouse.Target
		local char = target.Parent
		local player = game.Players:GetPlayerFromCharacter(char)
		mouse.Button1Down():connect(function()
			if player then
				local pTeam = player.Team
				player.Team = "Jailed"
				char.Humanoid.Health = 0
				wait(120)
				player.Team = pTeam
			end
		end)
	end
end)

tool.Unequipped:connect(function()
	canArrest = false
end)


1 answer

✓ Accepted answer

mouse.Button1Down:connect(function() not mouse.Button1Down():connect(function()

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