Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.