First off, I will start by saying that I am an inexperienced scripter, but I have a background in web design. Being that I just started developing on Roblox a week ago I have been breaking down many models and learning the scripts, editing to see what makes them tick etc.
I am having troubles figuring something out. After reading countless threads I have seen many people frown on free models, so please excuse me from the get go, but alongside reading a great deal, I have been using some free models (KittehRPG) to learn through trial and error. I do use Ro-Defender, and have really limited my usage beyond figuring out these starting blocks so I can do more on my own through time.
I have had many successes over the past week, but this one here is really stumping me. I have two swords, along with two different sword scripts, and one has much improved animations. I have been trying to take those animations and drop them into the old weapon, and then applying the new animations to the old weapon.
I know they work with the model, because if I copy the improved animations themselves, as well as the script that pairs with them, and then place them in the old weapon (deleting my other script from the old model), it works flawlessly and the old weapon then uses the new animations. Unfortunately it will not then use any of my damage modifiers, xp evaluators, etc.
After tirelessly attempting to take components of the new, improved script, as well as the new animations, and applying only the animation portions of the script, while removing the old animations, and also leaving the other portions of the script still functioning, I have been unsuccessful.
Now, I already can speculate what components are triggering the animations, but after many attempts to pinpoint and edit only the needed elements, I have not had any luck. Here is the old script elements that I feel are triggering the animations:
function attack() local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Slash" anim.Parent = Tool end function lunge() local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Lunge" anim.Parent = Tool force = Instance.new("BodyVelocity") force.velocity = Vector3.new(0,4000,0) --Tool.Parent.Torso.CFrame.lookVector * 80 force.Parent = Tool.Parent.Torso wait(.25) swordOut() wait(.25) force.Parent = nil wait(.5) swordUp() damage = slash_damage end function swordUp() Tool.GripForward = Vector3.new(-1,0,0) Tool.GripRight = Vector3.new(0,1,0) Tool.GripUp = Vector3.new(0,0,1) end function swordOut() Tool.GripForward = Vector3.new(0,0,1) Tool.GripRight = Vector3.new(0,-1,0) Tool.GripUp = Vector3.new(-1,0,0) end function swordAcross() -- parry end Tool.Enabled = true function onActivated() if not Tool.Enabled then return end Tool.Enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then return end attack() wait(1) Tool.Enabled = true end function onEquipped() end script.Parent.Activated:connect(onActivated) script.Parent.Equipped:connect(onEquipped) connection = sword.Touched:connect(blow)
Here is the script that comes from the improved weapon:
sp = script.Parent r = game:service("RunService") debris = game:GetService("Debris") anims = {"RightSlash","LeftSlash","OverHeadSwing","LeftSwingFast","RightSwingFast"} Sounds = {{145180512, "Metal"}, {145180522, "Metal"}, {145180533, "Wood"}, {145180541, "Wood"}, {145180529, "Slash"}, {145180550, "Slash"}} WoodSounds = {} MetalSounds = {} SlashSounds = {} basedamage = 10 slashdamage = 50 swingdamage = 60 damage = basedamage sword = sp:WaitForChild('Handle') sp.Taunting.Value = false local UnsheathSound = Instance.new("Sound") UnsheathSound.SoundId = "http://www.roblox.com/Asset/?id=145180523" UnsheathSound.Parent = sword UnsheathSound.Volume = .2 for _,Sound in pairs(Sounds) do local S = Instance.new("Sound") S.SoundId = "http://www.roblox.com/Asset/?id=" .. Sound[1] S.Parent = sword S.Volume = .2 if Sound[2] == "Wood" then table.insert(WoodSounds, S) elseif Sound[2] == "Metal" then table.insert(MetalSounds, S) elseif Sound[2] == "Slash" then table.insert(SlashSounds, S) end end function waitfor(parent,name) while true do local child = parent:FindFirstChild(name) if child ~= nil then return child end wait() end end waitfor(sp,"Taunting") waitfor(sp,"RunAnim") local Halt = false; function blow(hit) if hit:findFirstChild("IsShield") then damage = 0 pcall(function() if hit.IsShield.Value == "Wood" then WoodSounds[math.random(#WoodSounds)]:Play() elseif hit.IsShield.Value == "Metal" then MetalSounds[math.random(#MetalSounds)]:Play() else WoodSounds[math.random(#WoodSounds)]:Play() end end); return end if Halt then return end; Halt = true; if hit.Parent ~= nil then local humanoid = hit.Parent:findFirstChild("Humanoid") local vCharacter = sp.Parent if vCharacter ~= nil then local vPlayer = game.Players:playerFromCharacter(vCharacter) if vPlayer ~= nil then local hum = vCharacter:findFirstChild("Humanoid") if humanoid ~= nil then if hum ~= nil and humanoid ~= hum then local right_arm = vCharacter:FindFirstChild("Right Arm") if right_arm ~= nil then local joint = right_arm:FindFirstChild("RightGrip") if joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword) then tagHumanoid(humanoid,vPlayer) humanoid:TakeDamage(damage) wait(.3) end end end end end end end Halt = false; end function tagHumanoid(humanoid,player) for i,v in ipairs(humanoid:GetChildren()) do if v.Name == "creator" then v:Destroy() end end local creator_tag = Instance.new("ObjectValue") creator_tag.Value = player creator_tag.Name = "creator" creator_tag.Parent = humanoid debris:AddItem(creator_tag,1) end sp.Enabled = true function onActivated() if sp.Enabled and not sp.Taunting.Value then sp.Enabled = false local character = sp.Parent; local humanoid = character.Humanoid if humanoid == nil then print("Humanoid not found") return end SlashSounds[math.random(#SlashSounds)]:Play() local newanim = anims[math.random(1,#anims)] while newanim == sp.RunAnim.Value do newanim = anims[math.random(1,#anims)] end sp.RunAnim.Value = newanim if newanim == "OverHeadSwing" then damage = swingdamage else damage = slashdamage end wait(.75) damage = basedamage sp.Enabled = true end end function onEquipped() UnsheathSound:play() end sp.Activated:connect(onActivated) sp.Equipped:connect(onEquipped) connection = sword.Touched:connect(blow)
So to reiterate, how can I take ONLY the animation portions from the improved script and replace the old animation triggers from the old script?
The new, improved script is confusing, because it seemingly adds damage modifiers in with the animations, and this is making it very complicated pruning out ONLY the animation modifiers to apply into the old model, as I wish to retain the damage values in the old code.
Sorry for my long-winded explanation, I am just trying to be as detailed as possible as this is my first post here, and I am looking for somebody to get me on the right track. Through the past week I came across many hardships, but I have done mass trial and error and have had many successes. This one is just not co-operating.
Thanks for any help or guidance.
The first sword does not use typical roblox animations. It "animates" the character by changing positions & rotation via script. Some people call that "scripted animations".
The second script seems to only have a little to do with the animations. There has to be something more...
...just publish what you got, send me a link and I'll see what we can do.
Thanks for the response. The game is in very early alpha and is not going public or being published yet, however, I am pasting the full codes of both weapons into pastebin for you to review in hopes that somebody can help me merge the new animations into the old script and still have it functioning. Even if I published the game publicly, the only thing you would see is that one animation looks better than the other.
Just want to mention again, if I copy paste the script from the new model into the old model it does in fact work with the old model, and all I did to achieve this was place the new animations into the old model, as well as the new script. Loaded up the game and the old model was now using the new animations, and it looked great.
My problem is merging the new animation components into the old script, this is proving to be very challenging. Any help is much appreciated, this will improve the animations for all swords in my game ten fold.
Here is the pastebin containing both full scripts: https://pastebin.com/G70qYGz1