TO BE MORE PRECISE:I believe the problem is at line 5, where it clones it prematurely from the ServerStorage rather than moving the chick to the egg. I have an egg script that will hatch an NPC when something gets near it, however the first time it spawns where the NPC's location is at (in ServerStorage) and after the script has re-enabled itself, the script works like how I intended it. Detail: I touch the egg, it plays the audio and spawns the NPC far away. When I go back and try it again, the NPC spawns on the egg (like I intended). Code:
function touch(hit) local chick = game.ServerStorage:WaitForChild('chick') local open = script.Parent.Open --the sound local rootPart = script.Parent --the egg local chickBaby = chick:Clone() --maybe why it spawns away from the egg? wait(2) open:Play() wait(3) script.Disabled = true chickBaby:Clone() chickBaby.Parent = workspace chick:SetPrimaryPartCFrame(rootPart.CFrame) wait(20) script.Disabled = false end script.Parent.Touched:connect(touch)
I believe the issue is because you arent checking if hit is a player, so when it spawns and touches the ground, the function runs and disables itself prematurley. To fix this, add in between lines 1 and 2:
if not hit.Parent:FindFirstChild("Humanoid") then return end
that should prevent the code from firing when touching non players!
I figured it out by playing with the script. Apparently local chickBaby is not needed and can function fine with just chick. That is why the chick would spawn somewhere else instead of the egg.