Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Which elements of this old script do I need to replace for new weapon animations?

Asked by 7 years ago

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.

2 answers

Log in to vote
0
Answered by 7 years ago

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.

Ad
Log in to vote
0
Answered by 7 years ago

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

0
I ment publishing the swords as free models, so I could take a look at them (right click -> save to roblox). Anyways, are you sure that the new sword doesn't have any other scripts? Programical 653 — 7y
0
Ok I see what you mean now. I have published both as free models now. You can find the sword with the improved animations at the following link: https://www.roblox.com/library/750180197/Standard-Sword-with-Animations ~ and you can find the old wooden sword with the old, fairly poor animation here: https://www.roblox.com/library/750180844/Wooden-Sword ~ Thanks again! JediRift 5 — 7y
0
Oh my, these scripts are such a mess. Programical 653 — 7y
0
I was hoping I could explain everything. I can't. There were way too many changes I had to make. I suggest you make your own sword, from scratch. These scripts had a lot of junk and deprecated stuff inside of them. This is why you shouldn't learn from free models. Anyways, here is the fixed (?) sword, with the fancy animations and some helpful comments: https://www.roblox.com/library/750408641/Jed Programical 653 — 7y
View all comments (25 more)
0
This is fantastic work, I can't thank you enough and I loved the "nopenopenope" comment, haha! Two quick things: #1 - The sword no longer has sounds. Is there a way to implement the unsheath and swinging sounds that the old model has? #2 - The other sword also sort of spins/rotates in hand when attacking. I did like that. Can that animation be placed in? Really appreciate everything you've done!!! JediRift 5 — 7y
0
Well, if you take a look at the "LocalGui" script of the iron sword, there is a function called "spinsword" or something like that. Just take the function and the variable declarations from the beggining of the script, move all that to my "Animate" script in the wooden sword, and call it wherever you want. For the sounds - my "Animate" script comes with an attack, equipped and unequipped function. Programical 653 — 7y
0
Play the sounds inside these functions. Detailed tutorial (official): http://wiki.roblox.com/index.php?title=Sounds Programical 653 — 7y
0
By the way, the sword spinning is a scripted animation. Programical 653 — 7y
0
Ok thanks, so far I got the unsheath sound working, so that is a start. The trouble I am having is with the grip commands, as well as playing the slash sounds at all. This current edit of your script does the unsheath sound now, but nothing else. JediRift 5 — 7y
0
https://pastebin.com/hxsfSmwJ - So with the other sword it has all these grip commands, etc. any time I try to paste them in to trigger the spin, the sword stops working at all. Also not too sure where to place those slash sounds to be occurring at random. JediRift 5 — 7y
0
Output? Errors? Warnings? Programical 653 — 7y
0
For the sounds - don't try to copy the original creator's overcomplicated method - do like I did with the animations. Place some sounds you want inside a folder inside of handle, put them into an array with GetChildren(). You got the Play() part right though :) Programical 653 — 7y
0
Darn, I am totally lost. For the last four hours I have tried everything so I could return with some success. Tried your method, got as far as creating a folder. Did not know where to start the array or how to write it properly. As for spin, there is no output error from the code I placed above. It just doesn't trigger. JediRift 5 — 7y
0
I'm way over my head here. Sorry for being such a rookie. I can't even figure out how to get these sounds to work, I read over that tutorial, but when working it into my script I have no clue. Same with the spin animation. JediRift 5 — 7y
0
With the spin animation, if I use the script above, the sword still works, and does the unsheath sound, but no other sounds, and the spin animation does not work, nor print an error. If I move parts of where I pasted the spin animation, or add other code from the other source, the sword equips, but does not swing at all. JediRift 5 — 7y
0
You have to call spinsword(spintime) somewhere. Programical 653 — 7y
0
You might want to go back to http://wiki.roblox.com/index.php?title=AllTutorials Programical 653 — 7y
0
Thanks, will look over this tonight and get back to you soon. JediRift 5 — 7y
0
Welp, I added the folder to handle and added and named sounds in it. Then I added this script inside the handle: https://pastebin.com/tA7RbDjM ~ It seems the sword swings, but no sounds, and no output error. I will need to spend more time with the Lua tutorials. Obviously I can not follow these directions and am off-track in the tiniest details. JediRift 5 — 7y
0
Regarding having to "call spinsword(spintime) somewhere", I tried looking up calling items, and tried adding it into the function attack call in your animate script. But I get an error. Here is the script edit I did trying to call the function: https://pastebin.com/ERQu7exR JediRift 5 — 7y
0
Although the sword still equips and plays unsheath sound, as well as swing, it outputs this error on every swing: 21:22:16.921 - Stack Begin 21:22:16.922 - Script 'Players.Player1.Backpack.Wooden Sword.Animate', Line 30 21:22:16.922 - Stack End 21:22:17.795 - Players.Player1.Backpack.Wooden Sword.Animate:30: attempt to call global 'spinsword' (a nil value) JediRift 5 — 7y
0
Also, I just want to say thanks again for all of your help. I appreciate that you aren't just handing me the script, but taking the time to educate me through my errors. I have a lot to learn, obviously, but I do believe this is giving me some good starter blocks, and I hope that in the end I can get both of these working. JediRift 5 — 7y
0
Based on this article, as well as regarding the sound, I have no clue why these are not working. As far as I can tell, that function on spinsword is being called and should trigger: https://pastebin.com/1hhr3VSa - Yet nothing happens. If I add a new function attack or on mouse click, it stops working. Super frustrating. JediRift 5 — 7y
0
The sound, there is no error. I placed this script: https://pastebin.com/NNxeaPr4 ~ inside the handle, along with the folder of the two slash sounds. Nothing happening at all. What am I doing wrong? I am following these very basic links you are posting, but when editing these scripts there are too many things unexplained in these articles pertaining to my circumstances. JediRift 5 — 7y
0
You're not calling spinsword(), only declaring it, unless I missed something. In the second script, you never call nor connect onActivated(), you just declare it. Programical 653 — 7y
0
Stop trying to learn using free models. You don't even understand the basics. https://scriptinghelpers.org/guides/lua-quick-start-guide | http://wiki.roblox.com/?title=Scripting Programical 653 — 7y
0
Programical, if you're out there - you really helped me learn so much through this series of posts / the scripts we worked on. Thank you! JediRift 5 — 3y

Answer this question