Script fails the first time, but the second and after it works like it should?
Asked by
5 years ago Edited 5 years ago
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:
02 | local chick = game.ServerStorage:WaitForChild( 'chick' ) |
03 | local open = script.Parent.Open |
04 | local rootPart = script.Parent |
05 | local chickBaby = chick:Clone() |
09 | script.Disabled = true |
11 | chickBaby.Parent = workspace |
12 | chick:SetPrimaryPartCFrame(rootPart.CFrame) |
14 | script.Disabled = false |
18 | script.Parent.Touched:connect(touch) |