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

Unable to cast value to objects? When using SubtractAsync?

Asked by 5 years ago

Basically, I want to create a "Square shaped" hole in the ground, but this error prevents me from doing so.

Here's the code:

Server

remote.OnServerEvent:Connect(function(player,data)
    if data and data["P"] then
        if data.P == "CreatePunjiTrap" then
            local d = data
            local newpart = Instance.new('Part')
            newpart.Parent = workspace
            newpart.Anchored = true
            newpart.Position = d["Pos"]
            newpart.Size = Vector3.new(10,5,10)
            local oof = {}
            table.insert(oof,d["Part"])
            local new = d["Part"]:SubtractAsync(d["Part"])
            d["Part"]:Destroy()
            newpart:Destroy()
            new.Parent = workspace
end
end
end)

local script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local remote = game.ReplicatedStorage.MasterRemote
mouse.Button1Down:Connect(function()
    remote:FireServer({["P"]="CreatePunjiTrap",["Pos"]=mouse.hit.p,["Part"]=mouse.Target})
end)
0
SubtractAsync takes an array as an argument, so wrap your part(s) in curly braces {d["Part"]} User#19524 175 — 5y
0
@incapaz that works, but now I got a new error, attempt to index local 'new' (a nil value) KamikazeShard 23 — 5y

Answer this question