Bone attack that creates bones in the ground behind it as it travels only has the first trail bone work

I’m trying to make this attack in my fighting game based on Undertale called the ‘Trailing Bone’; you throw this large bone that travels forward in a straight line, every so often it will make a bone rise from the ground behind it.


(Pictured: The red line is the direction in which the big bone moves, the blue bone outlines are the bones that are supposed to rise from the ground behind the bone, the cyan arrows indicate said bones rising from the ground)

The first trail bone seems to work just fine according to the script, but every other bone that follows it do absolutely nothing.


The invisible highlighted bones are the ones that don’t work, the upright bone is the one that works properly.

Here’s the code that makes the big bone move and also spawns the trail bones in question:

x=0
while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-3,0,0) --The line of code that makes the large bone move
	x+=1 --This value is the script's 'tick,' if it reaches ten then it will spawn a trail bone as seen below
	if x >= 10 then
		x=0
		g = game.ReplicatedStorage.boneTrail:Clone()
		g.Parent = script.Parent.Parent
		g.PrimaryPart = g.Union
		g:SetPrimaryPartCFrame(script.Parent.CFrame * CFrame.new(0,0,0))
		g.Script.Disabled = false --I created a script within the model that contains the bone itself that puts it inside the 'bones' Model in the attack itself and then deletes the now empty model, you will see why later on
	end
	task.wait()
end

image
This is the attack itself; the Union is the large bone, appear is what sets it up (fading in, activating the hurt and move scripts, the deletion after certain time has passed). the lines of code you saw earlier were all part of the ‘move’ script inside the Union. the ‘bones’ Model is where the trail bones get put into. I will now delve into the ‘boneManager’ script and it’s contents.

bone = script.Parent
while true do
	for i, bone in ipairs(bone:GetChildren()) do --Some code that grabs all the Union parts inside the model and applies everything inside the code to every single one of those Unions at once. I know I could just have the spawned trail bones just have their own move scripts but I'm doing this way to hopefully try and reduce lag that would normally be caused from doing just that.
		if bone:IsA("UnionOperation") and bone.yoink.Value == false then
			bone.yoink.Value = true --The value I put inside the trail bone to make sure the script only affects bones that haven't already been activated
			bone.Transparency = 0
			bone.yVal.Value = script.Parent.Parent.Union.Position.Y --This sets the value to the Y position of the large bone
			bone.Orientation = Vector3.new(0,0,script.Parent.Parent.Union.Orientation.Z)
			bone.Position = Vector3.new(bone.Position.X, (bone.yVal.Value)-20, bone.Position.Z)
			task.wait(0.25)
			bone.owie.Disabled = false
			for i = 1,10 do
				bone.Position += Vector3.new(0,2,0)
				task.wait()
			end
			bone.bam:Play()
			task.wait(10)
			for i = 1,20 do
				bone.Position -= Vector3.new(0,1,0)
				task.wait()
			end
			bone:Destroy()
		end
	end
	task.wait()
end

This is what the inside of the trail bone looks like.
image
Here are the contents of the currently disabled ‘Script’ inside the trail bone.

script.Parent.Union.Parent = script.Parent.Parent.bones
script.Parent:Destroy()

So far I have tried creating a function for the boneManager script because I do think that the task.wait() segments of the script might be the problem, but every single time I’ve attempted that it just acts like the bone doesn’t exist. I’ve tried renaming the ‘yoink’ value to what it is now, it used to just be called ‘active,’ I thought maybe that could be the problem since if you name parts certain things when trying to do certain things in a script it won’t work because it has the same name as a certain function, but it turns out that didn’t make any difference. I originally had the “if bone:IsA(“UnionOperation”)” part have the UnionOperation be ‘Model’ or ‘DataModel’ because I didn’t know which one meant the Model property (or if it even applies to this line of code) and originally it would paste the entire model of the trail bone into the ‘bones’ Model, but that had the same results as what I’m doing now.

I know the script was probably more optimized when it was doing the ‘Model’ thing in the IsA:() code but honestly I’m just very tired at the time of writing this, I have somewhere to be tomorrow and to be quite frank with you this has just been frustrating me all night long. If anybody has a solution to this then please do let me know. Thank you!

Just to confirm some things:

  • Are you certain that the bones aren’t spawning, rather than just being positioned somewhere else
  • If you add print statements into the movement script, can you please confirm that the code does keep on running correctly.
2 Likes
  1. As I’ve said in the original post; they are indeed spawning in as they’re supposed to, they just won’t do the stuff listed in the boneManager script (Rise up from the ground, linger for a bit then descend back and destroy itself).

  2. I put print statements into both the move script (specifically the part where it spawns the bones) and the boneManager script:
    image
    The spawning is not the issue it seems, though one thing I did notice is that the boneManager script takes over ten seconds to do what it’s supposed to for the next bone, so I do think the task.wait() portions of that script may be hindering the script’s ability to do that for the rest of the bones.
    Though I don’t really quite know what to do as I’ve already tried using a function() but it didn’t register that the bone even existed.