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 4 years ago
Edited by Ziffixture 4 years ago

This question has been solved by the original poster.
01local Part = Instance.new("Part")
02 
03Part.Position = Vector3.new(0,20,0)
04Part.Parent = workspace
05 
06Part.Touched:Connect(function()
07    local RedPart = Instance.new("Part")
08    RedPart.Position = Part.Position
09    Part:Destroy()
10    RedPart.Transparency = 1
11    RedPart.Size = workspace.Part.Size
12    RedPart.Anchored = true
13 
14    RedPart.Parent = workspace
15    RedPart:SubtractAsync(workspace.Baseplate)
16end)

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 4 years ago

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

01local Part = Instance.new("Part")
02 
03Part.Position = Vector3.new(0,20,0)
04Part.Parent = workspace
05 
06Part.Touched:Connect(function()
07    local RedPart = Instance.new("Part")
08    RedPart.Position = Part.Position
09    RedPart.Transparency = 1
10    RedPart.Size = workspace.Part.Size
11    Part:Destroy()
12    RedPart.Anchored = true
13 
14    RedPart.Parent = workspace
15    RedPart:SubtractAsync(workspace.Baseplate)
16end)

That should work

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

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

1RedPart:SubtractAsync(workspace.Baseplate)

instead of

1RedPart:SubtractAsync({workspace.Baseplate})

tho your code didnt fix my issue but thanks anyways

Answer this question