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

why do i get "Unable to cast value to Objects" error when running this code? [Solved]

Asked by 3 years ago
Edited by Ziffixture 3 years ago

This question has been solved by the original poster.
local Part = Instance.new("Part")

Part.Position = Vector3.new(0,20,0)
Part.Parent = workspace

Part.Touched:Connect(function()
    local RedPart = Instance.new("Part")
    RedPart.Position = Part.Position
    Part:Destroy()
    RedPart.Transparency = 1
    RedPart.Size = workspace.Part.Size
    RedPart.Anchored = true

    RedPart.Parent = workspace
    RedPart:SubtractAsync(workspace.Baseplate)
end)

im trying to make a part that falls down the air and when it touches the baseplate it removes part of the baseplate

2 answers

Log in to vote
0
Answered by 3 years ago

You destroyed part before you accessed it's size. Change your code to this:

local Part = Instance.new("Part")

Part.Position = Vector3.new(0,20,0)
Part.Parent = workspace

Part.Touched:Connect(function()
    local RedPart = Instance.new("Part")
    RedPart.Position = Part.Position
    RedPart.Transparency = 1
    RedPart.Size = workspace.Part.Size
    Part:Destroy()
    RedPart.Anchored = true

    RedPart.Parent = workspace
    RedPart:SubtractAsync(workspace.Baseplate)
end)

That should work

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

i fixed my problem it was because on line 15 it was

RedPart:SubtractAsync(workspace.Baseplate)

instead of

RedPart:SubtractAsync({workspace.Baseplate})

tho your code didnt fix my issue but thanks anyways

Answer this question