:SubstractAsync returning "Unable to cast value to Objects"

I want to create a Union through a script.

The issue is that it’s only returning “Unable to cast value to Objects” and not creating a union.

I couldn’t find anybody else who had this issue with unions/

LOCAL SCRIPT:

local player = game.Players.LocalPlayer
local RS = game.ReplicatedStorage
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
	local loc = mouse.Hit.Position
	RS.Pos:FireServer(loc)

	
end)

SERVER SCRIPT:

local RS = game.ReplicatedStorage
local part = game.Workspace.Part
local function pos(player, loc)
	local bull = RS.Bullet:Clone()
	bull.Parent = workspace.Parts
	bull.Position = loc
	wait(00001)
	local union = part:SubtractAsync(bull)
	union.Parent = workspace
	


end
RS.Pos.OnServerEvent:Connect(pos)
1 Like
local RS = game.ReplicatedStorage
local part = game.Workspace.Part
local function pos(player, loc)
	local bull = RS.Bullet:Clone()
	bull.Parent = workspace.Parts
	bull.Position = loc
    local Parts = {bull}
	wait(00001)
	local union = part:SubtractAsync(Parts)
	union.Parent = workspace
	


end
RS.Pos.OnServerEvent:Connect(pos)

When I see Async I always think it deals with an array so maybe this?

2 Likes

You might need to put it in a table.

Replace your server script with this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local part = workspace.Part

--//Functions
ReplicatedStorage.Pos.OnServerEvent:Connect(function(player, position)
	if not position or typeof(position) ~= "Vector3" then
		return
	end
	
	local bull = ReplicatedStorage.Bullet:Clone()
	bull.Position = position
	bull.Parent = workspace.Parts
	
	local union = part:SubtractAsync({bull})
	union.Parent = workspace
end)

I also added some sanity checks so the script won’t error if an invalid position is sent.

@OwlCodes beat me to it lol

2 Likes

Thanks dude! You saved me from doing a bunch of digging!

1 Like

Sorry, haha. You put in more effort which I appreciate.

2 Likes

Oh, I apologize. You also want to use task.wait()

task.wait(0.1) -- Replace with any time you want to wait.