Animals falling through the ground

I am making a “Grow a garden” type of game, but with animals.
The problem occurs when the player places an egg, out of which the animal comes out. The animal usually works just fine and gets spawned in, but in rare occasions, it falls through the ground.
I’ve tried searching, thinking, a lot of ChatGPT… but nothing worked. I made all of the parts in my model massless, CanCollide off and Anchored Off.

local originalSize = egg.Size
 local targetSize = egg.Size * 2
 local yOffset = (targetSize.Y - originalSize.Y) / 2

 local growGoal = {Size = targetSize, CFrame = cFrame * CFrame.new(0, yOffset, 0)}
 local animal = SS.Animals:WaitForChild(animal):Clone()

 for _, part in ipairs(animal:GetDescendants()) do
  if part:IsA("BasePart") then
   part.CollisionGroup = "Animal"
   part.Massless = true
  end
 end

 local animalHeight = animal.PrimaryPart.Size.Y 
 local spawnCFrame = egg.CFrame + Vector3.new(0, egg.Size.Y / 2 + animalHeight / 2 + 0.4, 0) 
 animal:PivotTo(spawnCFrame)

 TW:Create(egg, TweenInfo.new(1.25, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0.15), growGoal):Play()
 task.wait(1.25)
 TW:Create(egg, TweenInfo.new(.1), {Size=Vector3.new(0,0,0)}):Play()

 local particles = RP.Confetti:Clone()
 particles.CFrame = egg.CFrame
 particles.Parent = game.Workspace

 local n = math.random(1, 1000)
 local result = getRandomRarity(n)

 local scale = Animal.Round(result.scale)
 local price = Animal.Round(scale * animal.Price.Value)
 local mutation = math.random(1,100)

 if mutation == 100 then
  price = Animal.Round(price * 5)
  animal.Mutation.Value = "RAINBOW"
 elseif mutation >= 97 then
  price = Animal.Round(price * 3)
  animal.Mutation.Value = "GOLDEN"
 end

 Mutations.applyMutation(animal.Mutation.Value, animal)

 animal.Price.Value = price
 animal.PrimaryPart.Animal.Frame.Value.Text =  price .."$"
 animal.Scale:SetAttribute("targetScale", scale)
 
 animal.Parent = plr.Plot.Value.Animals
 task.wait(0.1)

Any help is greatly appreciated!

You said you made all the parts cancollide off, making the parts cancollide off means they would just phase through blocks. if you turn all parts cancollide off, that means it will fall through. before you spawn it it make sure cancollide is on

I thought it didn’t need CanCollide on, as it usally worked without it. I’ll test it and will let you know if it works! Thanks for your response!

1 Like

use Collision Groups
Collision Groups allow you to configure how parts collide with each other
You could make players have no collision with the animals and still have the player collide with the map
that way you can have the animals collide with the map but not collide with players

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.