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
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.
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!