So I’m trying to make something go to the ground when it spawns it, and I have no clue how to go about this, I looked everywhere and couldn’t find something that would work
the script brings it from lighting into workspace, I need a way to bring it down to the ground whenever it gets brought into workspace
Provided your ground would usually be mostly flat, you can use a raycast from the part downwards in order to figure out what the Y coordinate should be and CFrame it there.
If you expect to have more bumpy terrain, the same philosophy still applies, but you can calculate rotation tweaks to make it fit better with a raycast’s normal vector. Given your part’s shape, it’ll likely never be perfect, but it should be fairly decent.
Yessir, a raycast does not guarantee it’ll hit something. When that happens, it’ll return nil.
This means that you should check that the raycastResult actually exists:
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult then
script.Parent.Position = raycastResult.Position
end
This will solve any errors.
Theoretically in some cases, your ray could be too short or will never have anything in its path, so you may have to increase its length or alter the ray a tad. However, if you said it works aside from the errors, you should be okay.
If it repeats it is most probably because you are checking when it Changes, it will repeat a raycast because its property is changing (position or whatever), you should use GetPropertyChangedSignal to check when its parent changes, check if its workspace, and raycast to find the nearest object by the Y axis.