So, I am trying to make a script that can make a spring constraint hook onto your arm and what your mouse is at. So far, I got this
local lassos = {} local lasso = game.ReplicatedStorage.MakeLasso local mouse = game.Players.LocalPlayer:GetMouse() local gui = Instance.new('ScreenGui', game.Players.LocalPlayer.PlayerGui) gui.Enabled = false local function MakeButton(instance) --some UI to destroy constraints print(instance:GetFullName()) local new = Instance.new('TextButton', gui) new.TextScaled = true new.TextWrapped = true new.Text = instance.Attachment1.Parent.Parent.Name..'.'..instance.Attachment1.Parent.Name new.Style = Enum.ButtonStyle.RobloxButtonDefault new.TextColor3 = Color3.new(1, 1, 1) new.MouseButton1Click:Connect(function() if instance.Attachment0 == nil then new:Destroy() return end instance.Attachment0:Destroy() instance.Attachment1:Destroy() instance:Destroy() new:Destroy() end) end do --makes gui local gc = Instance.new('UIGridLayout', gui) gc.CellPadding = UDim2.new(0, 10, 0, 10) gc.CellSize = UDim2.new(0, 100, 0, 50) end script.Parent.Parent.Activated:Connect(function(mouse) local mouse = game.Players.LocalPlayer:GetMouse() local plyr = script.Parent.Parent.Parent local hand = plyr:FindFirstChild('RightHand') or plyr:FindFirstChild('Right Arm') if mouse.Target and mouse.Target:IsA('BasePart') and hand then local a0 = hand local a1 = mouse.Target local lasso = lasso:InvokeServer(a0, a1, 'Create') if lassos == nil then lassos = {} return end for _, object in pairs(lasso) do table.insert(lassos, object) end MakeButton(lasso[1]) end end) script.Parent.Parent.Unequipped:Connect(function() for _, object in pairs(lassos) do lasso:InvokeServer(object, '', 'Destroy') end lassos = {} for _, obj in pairs(gui:GetChildren()) do if obj:IsA('Frame') then obj:Destroy() end end end) local user = game:GetService('UserInputService') local deb = false user.InputBegan:Connect(function(key) local target = mouse.Target if not deb and key.KeyCode == Enum.KeyCode.T and user:GetFocusedTextBox() == nil and target ~= nil and target:IsA('BasePart') then deb = true if lassos == nil then lassos = {} deb = false return end for i, tie in pairs(lassos) do if tie:IsA('SpringConstraint') then print('s') local a0 = target if tie.Attachment1.Parent then lasso:InvokeServer(a0, tie.Attachment1.Parent, 'Create') tie.Attachment0:Destroy() tie.Attachment1:Destroy() tie:Destroy() end end end lassos = {} deb = false elseif key.KeyCode == Enum.KeyCode.F2 then gui.Enabled = not gui.Enabled end end)
I know this is kinda bad remote event security, but I just want to play around with constraints.
I thought this would work, but when I run it, it errors Players.Player1.Backpack.Lasso.Handle.Lasso:42: bad argument #1 to 'pairs' (table expected, got nil)
. Nowhere in the script sets the table to nil. Also, I did if lassos == nil then lassos = {} end
statements to see if that fixed it, but for some reason it does not. Have any ideas?