I’ve been trying for the second day now to make a selection system by button holding. That when the player holding the button and clicked on a few parts they were selected and when you release the button the selection is applied and parts can be moved, change color, etc. But I tried many options and they were not working. I searched the entire forum and did not find an answer. So far I have stopped at this option. I will be very grateful for your help. Here is my script:
local Mouse = game.Players.LocalPlayer:GetMouse()
local CAS = game:GetService("ContextActionService")
local Handles = game.Players.LocalPlayer.PlayerGui:WaitForChild("Handles"):FindFirstChild("Handle")
local ArcHandles = game.Players.LocalPlayer.PlayerGui:WaitForChild("Handles"):FindFirstChild("ArcHandles")
local PlayerGUI = game.Players.LocalPlayer.PlayerGui
local debounce = false
local Selected = {}
local CountofPress = 0
for _, v in ipairs(workspace:WaitForChild("JustPlace"):GetChildren()) do
if v:IsA("BasePart") then
Mouse.TargetFilter = v
end
end
Mouse.Button1Down:Connect(function()
if game:GetService("CollectionService"):HasTag(Mouse.Target, "CanBeEdited") then
local CheckOwner = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("CheckIfPlayerOwnerOfThisPart"):InvokeServer(Mouse.Target)
local IsHolding = UserInputService:IsKeyDown(Enum.KeyCode.LeftControl)
if CheckOwner then
if IsHolding then
table.insert(Selected, Mouse.Target)
local Model = Instance.new("Model")
Model.Parent = workspace:WaitForChild("Parts"):WaitForChild(game.Players.LocalPlayer.Name.."_s folder")
for _, v in pairs(Selected) do
v.Parent = Model
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Parent = Model
SelectionBox.Adornee = Model
v:SetAttribute("IsActive", true)
--Handles.Adornee = Model
--ArcHandles.Adornee = Model
end
else
Selected = {}
for _, v in pairs(workspace:WaitForChild("Parts"):WaitForChild(game.Players.LocalPlayer.Name.."_s folder"):GetDescendants()) do
if v:IsA("SelectionBox") then
v:Destroy()
end
end
for _, v in pairs(workspace:WaitForChild("Parts"):WaitForChild(game.Players.LocalPlayer.Name.."_s folder"):GetChildren()) do
if v:IsA("Part") or v:IsA("Model") then
if v:GetAttribute("IsActive") == true then
v:GetAttribute("IsActive", v:SetAttribute("IsActive", false))
end
end
end
end
if CountofPress == 0 then
Handles.Style = Enum.HandlesStyle.Resize
Handles.Visible = true
elseif CountofPress == 1 then
Handles.Style = Enum.HandlesStyle.Movement
elseif CountofPress == 2 then
Handles.Visible = false
ArcHandles.Visible = true
elseif CountofPress >= 3 then
CountofPress = 0
Handles.Visible = true
ArcHandles.Visible = false
end
Handles.Adornee = Mouse.Target
ArcHandles.Adornee = Mouse.Target
local SelectionBox = Instance.new("SelectionBox")
SelectionBox.Parent = Mouse.Target
SelectionBox.Adornee = Mouse.Target
Mouse.Target:GetAttribute("IsActive", Mouse.Target:SetAttribute("IsActive", true))
PlayerGUI:WaitForChild("EditProperty").Enabled = true
if Mouse.Target.CanCollide == true then
PlayerGUI:WaitForChild("EditProperty"):WaitForChild("PropertiesFrame"):WaitForChild("ScrollingFrame"):WaitForChild("CanCollide").Text = "Collide: On"
else
PlayerGUI:WaitForChild("EditProperty"):WaitForChild("PropertiesFrame"):WaitForChild("ScrollingFrame"):WaitForChild("CanCollide").Text = "Collide: Off"
end
if Mouse.Target.CanTouch == true then
PlayerGUI:WaitForChild("EditProperty"):WaitForChild("PropertiesFrame"):WaitForChild("ScrollingFrame"):WaitForChild("CanTouch").Text = "Touchable: On"
else
PlayerGUI:WaitForChild("EditProperty"):WaitForChild("PropertiesFrame"):WaitForChild("ScrollingFrame"):WaitForChild("CanTouch").Text = "Touchable: Off"
end
if Mouse.Target.Anchored == true then
PlayerGUI:WaitForChild("EditProperty"):WaitForChild("PropertiesFrame"):WaitForChild("ScrollingFrame"):WaitForChild("Anchored").Text = "Anchored: On"
else
PlayerGUI:WaitForChild("EditProperty"):WaitForChild("PropertiesFrame"):WaitForChild("ScrollingFrame"):WaitForChild("Anchored").Text = "Anchored: Off"
end
end
else
Selected = {}
Handles.Adornee = nil
ArcHandles.Adornee = nil
for _, v in pairs(workspace:WaitForChild("Parts"):WaitForChild(game.Players.LocalPlayer.Name.."_s folder"):GetDescendants()) do
if v:IsA("SelectionBox") then
v:Destroy()
end
end
for _, v in pairs(workspace:WaitForChild("Parts"):WaitForChild(game.Players.LocalPlayer.Name.."_s folder"):GetChildren()) do
if v:IsA("Part") or v:IsA("Model") then
if v:GetAttribute("IsActive") == true then
v:GetAttribute("IsActive", v:SetAttribute("IsActive", false))
end
end
end
PlayerGUI:WaitForChild("EditProperty").Enabled = false
end
end)
local function ChangeHandle(ActionName, UserInputState, Obj)
if UserInputState == Enum.UserInputState.Begin then
CountofPress += 1
Handles.Style = Enum.HandlesStyle.Resize
if CountofPress == 1 then
Handles.Style = Enum.HandlesStyle.Movement
elseif CountofPress == 2 then
Handles.Visible = false
ArcHandles.Visible = true
elseif CountofPress >= 3 then
CountofPress = 0
Handles.Visible = true
ArcHandles.Visible = false
end
end
end
CAS:BindAction("Change", ChangeHandle, true, Enum.KeyCode.R)
Sorry about the bad script.
