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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
1
Answered by 7 years ago

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

Ad

Answer this question