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

Error with when on click change union csg?

Asked by
NEILASc 84
2 years ago
Edited 2 years ago

My error code is csg -21.

my code;

client localscript:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local createpart = game.ReplicatedStorage.createpart

local debris = game:GetService("Debris")

mouse.Button1Down:Connect(function()
    local Unitray = mouse.UnitRay
    local beam = Instance.new("Part",workspace) 
    local x = tonumber(mouse.Hit.X + "0") -- made it so its editable
    local y = tonumber(mouse.Hit.Y + "0")
    local z = tonumber(mouse.Hit.Z + "0")
    beam.BrickColor = BrickColor.new("Toothpaste")
    beam.FormFactor = "Custom"
    beam.Material = "Neon"
    beam.Transparency = 0.6
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false
    local distance = (mouse.Origin.p - mouse.Hit.p).magnitude
    beam.Size = Vector3.new(0.2,0.2,distance)
    beam.CFrame = CFrame.new(mouse.Origin.p, mouse.Hit.p) * CFrame.new(0, 0, -distance / 2)
    createpart:FireServer(Vector3.new(math.floor(x+.5),math.floor(y+.5),math.floor(z+.5)), math.random(2,10))
    debris:AddItem(beam,2)
end)

csg handler:

local destructable = workspace.Destructable
local tabl = {}

local function getcheckingparts()
    for i,taba in pairs(tabl) do
        table.remove(tabl,i)
    end
    for i,v in pairs(workspace:GetChildren()) do
        if v.Name == "checking" then
            table.create(#tabl,v)
        end
    end
end

while task.wait() do
    getcheckingparts()
    if workspace:FindFirstChild("checking") then
        local success, error, unionpart = pcall(function()
            return destructable:SubtractAsync(tabl)
        end)

        if success and unionpart then
            print("it works")
            unionpart.Position = destructable.Position
            unionpart.Anchored = true
            unionpart.Parent = game.Workspace
            destructable:Destroy()
            for i,v in pairs(tabl) do
                v:Destroy()
            end
            print("sucessfully did it")
        else
            print(error)
        end
    end 
end

create part:

local createpart = game.ReplicatedStorage.createpart

local debris = game:GetService("Debris")

createpart.OnServerEvent:Connect(function(client,position,number)
    repeat 
        number = number - 1
        local hitthingy = Instance.new("Part",workspace)
        hitthingy.Name = "checking"
        hitthingy.Anchored = true
        hitthingy.CanCollide = false
        hitthingy.Size = Vector3.new(5,5,5)
        hitthingy.Orientation = Vector3.new(math.random(-180,180),math.random(-180,180),math.random(-180,180))
        print(position)
        hitthingy.Position = position
        debris:AddItem(hitthingy,2)
    until number == 0
end)

heres where i put my scripts; https://ibb.co/6sC67ZZ

sorry it isnt clean. this is my first post. that is for questioning

Answer this question