Animated Tower Attacks - Tower Defense Tutorial #7
Vložit
- čas přidán 31. 05. 2024
- Another longish video with a lot of editing scripts but we bring together everything we've learned over the last few episodes by combining various scripts and getting our towers animating and attacking.
Rig Editor Plugin ► www.roblox.com/library/127434...
DISCORD ► / discord
TWITTER ► / gnomecoderblx
TIMESTAMPS►
0:00 Intro
0:32 Rigging and preparing towers
3:02 Creating Animations
6:00 Editing Animation Script
12:50 Removing placeholder animation
14:00 Merging tower scripts
19:15 Attack animations
23:20 Facing enemy
27:57 Outro
Great, simple and easy to follow tutorial for beginners!
Edit: i would also say, you upload alot, i don't no any other Roblox Studio Developer on CZcams uploading this quick! Great job GnomeCode! (Both great and fast)
Man, for 2+ years I have been looking for a tower defense game tutorial. Every 1-3 weeks I searched for a tutorial... and boom, an amazing tutorial has appeared on youtube! THANK YOU!
Same bro.
wow nice
100% same case for me! Im new to developing and this is walking through the steps and really immersing me into it and Im actually understanding scripting now!
this man is amazing, i followed a different one previously and it was very hard to follow, this right here is just god-tier. can't wait for this series to be finished
Was it by Boss Metro?
Your video tutorials are the most understandable I've seen right now
Thank you and Happy New Year
Even though I don't follow along with these tutorials, they still help me learn a lot of stuff about programming I didn't know before. Thanks GnomeCode! :)
Ikr
the only think i learnt is task.wait()
@@BloonPlays lmao
@@BloonPlays same lmao
To be honest this has been the best tower defence tutorial I’ve seen on youtube because it’s so much more simple and shorter than the others so keep up the good work I’m looking forward to the lobby and the cash system
Great to hear thank you, more videos on the way!
i think this is one of the few td tutorials, most of the td making videos are dev logs
@@MyNamesAveren true
@@GnomeCode when i try to do the FindNearestTarget function i write it exactly like you did but it doenst work. Can you please explain why? i wrote it like you did i dont understand
edit:i can send you a screen shot
edit2:when i switch the tower to a part it works just fine but when i make the local distance
(target.HumanoidRootPart.Position - newtower.HumanoidRootPart.Position).Magnitude
it just doesnt work but it didnt leave anything in the output
also i set the variable for newtower with all lowercase
@@guyfrommars1110 check the spelling
Let's go, another tutorial!! I'm watching this right now. Thanks gnome!
Notification gang 😎
Happy new year! I have just subscribed to you for being helpful! Thanks for making this series!
Happy new year Gnome! 2021 was a well deserved great year for this channel and am excited for what’s to come!
I love this since as a beginner myself i can still edit the scripts and all since i actually understand what and why(he does a great job at explaining). Keep it up!
Awesome, great to hear
@@GnomeCode when i try to do the FindNearestTarget function i write it exactly like you did but it doenst work. Can you please explain why? i wrote it like you did i dont understand
edit:i can send you a screen shot
edit2:when i switch the tower to a part it works just fine but when i make the local distance
(target.HumanoidRootPart.Position - newtower.HumanoidRootPart.Position).Magnitude
it just doesnt work but it didnt leave anything in the output
also i set the variable for newtower with all lowercase
@@guyfrommars1110 Same problem with me, did we ever figure out the problem?
@@guyfrommars1110 did you put the prinary parts
Great job dude! This tutorial is amazing and I cannot wait for the next video
Super simple and easy your the best coding YT and I'm exited for the next vid KEEP BEING THE BEST MAN!
Thank you SO MUCH for all of this work that you are doing just to show us how to make this! This is easily the best tower defense making tutorial on CZcams in my opinion. Whenever I have a problem I can always find an answer! Thank you for this!
These tower defense tutorials are amazing! If you aren’t already planning to, I would suggest thinking about creating a placing system more similar to other tower defense games perhaps, a deck of towers you can place, upgrading your towers, and all the lobby features such as spawning into different maps, buying, equipping, and sorting through your units. If you do continue through this series, I’m sure it’s going to be a huge hit and might inspire a couple more tower defense games to show their faces on Roblox! Super excited to see what you do next, great work as always Gnome :D
P.S. Oh, you can also plan to include interesting mechanics for some of the towers, such as being placed on cliffs, freezing, slowing, etc. Also enemy mechanics such as knocking out or stunning the towers around them. Great work as always!
P.S.S. lol this is brainstorming please don’t get the wrong idea, you don’t have to add any of this I’m just throwing out ideas
XD slow down buddy
Fr slow down. it takes very long to add such things and very hard to do.
it’s brainstorming
cliff towers can easily be done by putting the buildings roof in the folder where all the grass is
@@RichRBLX true, but those towers would also be able to be placed on grass, right? maybe an exclusively cliff tower would work better
That's some pro content. Keep up the good job!
happy new year! thanks for all the great tower defense tutorials!
Small tip for people watching:
If you want the tower to face the enemy instantly, in the Tower module script at line 32 (line visible in video on 26:57) remove the "Bodygyro" so it's HumanoidRootPart.CFrame = targetCFrame
Also obiously you will need to change the code at line 54 (line visible in video on 27:22) in the same script:
local CFrame = Instance.new("CFrameValue")
CFrame = Vector3.new(math.huge, math.huge, math.huge)
CFrame = newTower.HumanoidRootPart.CFrame
Great video btw, keep it up man 💪
THANK YOU DUDE I was stuck there I didn't know how to get past that
tysm!
Thanks You I Was Stuck There For 1 day
bro you're a legend tysm
TYSM I was stuck here for 2 days
Yo, this may sound sarcastic, but it was my dream to make a tower defence game, and you made that dream real : ) Thanks so much GnomeCode
Happy New Year! That's the best tutorial ever!
Thanks for doing all these tutorials!
I'm finally understanding how the tower defense system works now.
if your attack animation merges within the idle one, make sure your attack animation is set priority to Action when you make it, you can edit it later too, if you open it where you create/edit animations
dude you saved me on the last video and now you're saving me again???
Thanks
I just dont get it mine is action priority and its not looped. While my idle animation is looped and set to idle but they still merged
@@lordwigstyle8017 did you find out why?
@@Dylan-db2ol Nope i never found out, i gave up after trying for hours upon hours
It's always nice to see how others complete tasks.
no
fr
happy new years eve gnome! i hope you enjoy yourself!
Happy Summer GnomeCode! And thx for this tutorial
Hey GnomeCode could you maybe add a slinger on top of the castle tower like the big one that you don’t place down (if your going to keep it of course). Then it might look a little better.
If the attack animation and the idle animation overlap, make sure that they both have the same number of frames, ex(30frames in attack and 30frames in idle)
they still overlapped :(, I beleive it has something to do with the animation priorities, such as action and idle, but I can't find the 2 that play both of the full animation
@@Bunanahz Same, I'm still searching as well.
@@Bunanahz im here to save ur day (change idle to movement)
@@squiggleszit's not working there's nothing wrong with my scripts my tower is attacking idk what's the problem I think it's because I'm using motor6D but I made a new r6 rig with the same animations still overlaps
@@daSmokingToilet46 are they both different actions?
Happy new year gnomecode!
yoooooo, happy new year gnome!
if your attack animations arent working, even if you redid the script 10 times do the following:
1) make sure the idle animation is set to "Idle" in Priority, and the attack animation set to "Action" priority.
2) make sure the idle is looping and the attack isnt.
these helped me fix my animations
thanks you helped me
Can u share ur animations script?
Dude, thanks for the help!
Mine just give me error "Infinite yield possible on 'Workspace.Towers.Pistol:WaitForChild("Animations")'"
@@MarianHere me too
heres some things you might add "more towers" and "healthbars" and a "working base damage and lose" "wave texts" a "lobby" and "the enemy speed and enemy health" and a "boss" and a "shop where you buy towers" and "stun scripts" and "Win Script"
That's kinda cool idea!
Be patient GnomeCode will do something great soon!
Enemy speed and health is quite easy and it works like a charm, just go to Humanoid, and change "Health" + "MaxHealth" to whatever you want, and walkspeed to also whatever you want. If your zombie is half the size of a normal R6 avatar, I'd recommend keeping the walkspeed at more than 3.25.
Thats to prevent humanoid timeout (which happens when target doesnt reach destination in less than 8 seconds)
@@typicalaverage ye
@@typicalaverage well i just tackled that with waypoints in between path
also why the hell did roblox add humanoid timeout
even if they did add that
they should make it a parameter and not a auto
Love you vids especially your tutorials and I really like this tower defense series I how you post the game when its done I'm sure I'll have a good time.
happy new year gnomecode!
Could you do a little update or explanation on how to make the towers face the enemies since BodyGyro got deprecated and AlignRotation has a different workflow
yeah same
its deprecated? i use it
@@jinxed-trulySame
yeah no Fr....
For those who are having problems during the idle animation part, just remember to set your configuration folder name to "Animations" or to whatever you have your script to
I have it to animations, but After i place the tower it's idle doesnt work
@@lorlema7404set the animation to looping
I have mine but there are no error's and even in the placeholder the animation just straight up does not work
@@Winged_Earthdid you fix it? i have the same problem
@@sikoranowak7991 Well I did not but I found out why. The animation I made whenever I try to Import it it does not work. Idk if urs also has the same problem but...
I asked people on the roblox dev forum and they said it was a bug and I could not report it since I was only a member. So I ditched the game for now. If you have the same problem as me try a dif animation and see if it works if it does you have to make a new animation.
Happy new year too all! We've all made great accomplishments this year I bet. Next year will be even better
Yall i deadass dont want to make a td game but i watch these vids ro learn something and enjoy it at the same time, anyways HAPPY NEW YEAR FROM POLAND🇵🇱🇵🇱
Hi Gnome, I was wondering if later on. You will teach us how to make a lobby and elevators to teleport you into different maps?
I was thinking the same thing. Hoping he sees this comment
@@ajtriesedits1448 yea every single tower defense game tutorial I watch doesn’t teach how to make a full lobby, I really don’t know why
gnomecode my attack animation keeps looping even though i didnt set it to loop and the range is only 10. the enemies were out of range and the animation was still constantly playing
same
3 questions,Is it loop,Is it action,double check the ID or remake.
Same
@@alvinkohjirui123thanks I did that last one
This is really helping me make my tower defense game, where every player's towers are these "cards", with their own modifiers to make them unique.
How did you do the BodyGyros? They dont exist anymore
@@justnooberactually its working
@@justnoober it might look like it but they still work
@@justnoober i dont know if you still care but you can add in objects that you cant regularly put in studio using commands (ex: Instance.new("hfushfsiu")
Amazing tutorial once again
Hi Gnomecode, I love this series but I have encountered a problem, in the 4th episode, when I try to find the distance between parts, it says: "Position is not a valid member of Model Workspace.Model". I checked your code and my code and I cant find any differences. Heres my code if you want to check it out:
local tower = script.Parent
local enemy = workspace.Enemy
local distance = (tower.Position - enemy.Position).Magnitude
print(distance)
Thanks!
Remember that models do not have a 'position' property. In this episode I switched to using a model and so used HumanoidRootPart
@GnomeCode After seeing your reply, I turned my tower into a union and it worked! Thanks a lot
@@GnomeCode when i do humanoid root part with the towers nothing works for some reason i tried to use print to see if it works but it didnt do anything in the output
and there are no syntax errors in the output or prints or warnings just nothing
here is my code that i wrote ( the entire tower module)
local serverstorage = game.ServerStorage
local phys = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local SpawnTowerEvent = events:WaitForChild("PlaceTower")
local tower = {}
function FindNearestTarget(newtower)
local MaxDistance = 15
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newtower.HumanoidRootPart.Position)
print(newtower.HumanoidRootPart.Position)
if distance < MaxDistance then
nearestTarget = target
MaxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newtower)
local target = FindNearestTarget(newtower)
if target then
target.Humanoid:TakeDamage(5)
end
task.wait(3)
tower.Attack(newtower)
end
function tower.Spawn(player, name, cframe)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if towerExists then
local newtower = towerExists:Clone()
newtower.HumanoidRootPart.CFrame = cframe
newtower.Parent = workspace.Towers
newtower.HumanoidRootPart:SetNetworkOwner(nil)
for i, object in ipairs(newtower:GetDescendants()) do
if object:IsA("BasePart") then
phys:SetPartCollisionGroup(object, "Tower")
end
end
coroutine.wrap(tower.Attack)(newtower)
else
warn("the requested tower does not exist:", name)
end
end
SpawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
Thank you SO much for tis series! Not only can you add on more at the end, it is just so helpful because you aren’t just telling us to do but actually teaching us about things AND every time you do make a mistake (which is rare) you can always help us and are always replying to problems we have! Also you must have worked so hard finding out thus script and I just want to thank you for all of the episodes that you have done, you are a GREAT scripting youtuber!
thanks so much! I like tower defence tutorials!
I have requests:
Cash system
Base health
Lobby
Upgrading system
teleportation system to get to the maps like the other td games
And the player limit for each map (mega servers have the highest player limit and the normal servers have 1-4 player limit)
New health system for Mobs (when you hover over the mob it will show its health, if you dont want that just show the health above the mob)
Max towers system
More maps
Yes!
You don't have to tell him I mean he's obv gonna do all of those stuff bc that's the basic tower defense features
im making a tutorial of that too!
Uhm, does anyone know why my tower floats when I unanchor the HumanoidRootPart?
@@braidien_huangie idk lol
well planed tutorials. Thank you for Uploading Roblox scripting tutorials! your scripting Style is bit different but Very Interesting! Love your great work GnomeCode, Keep it up! Never Give up on this!!
Keep up the great work !
Im predicting part 8 is gonna be the base's health
HOW DID YOU PREDICT THAT WOOWWWW
epic
gaming@@tomo_tomato0923
Hey Gnome, currently I am having some problems with the bodygyro, whenever the tower is placed it starts floating and is basically flying about half a stud above the baseplate, help please xD
I figured out the problem sort of, basically bodygyro doesnt work on anchored parts. So I unanchored the humanoidrootpart because it had a bodygyro, but then it made the tower float because there were no anchored parts in the tower. Gnome, did you anchor your humanoidrootpart in this video?
EDIT: I FIXED IT HOORAY! It was because of the hipheight on my tower was making it float. I changed it back to 0 and just set the part of the code where it references and uses hipheight to just 1 stud.
Try rewatching the "placing towers" video.
@@HotMess_but it happened after i added the bodygyro lol
@@HotMess_ ok so here is the problem i figured out, bodygyro doesnt work on anchored parts so i unanchored the humanoidrootpart, but when i do that it makes the tower float because there is no anchored part in that tower. do you know if gnome had his hrp anchored in this video?
@@candykid44 change hipheight
@@GamrGuyReal if you press "read more" it tells you that I found out and fixed this problem 3 days ago, thanks anyways :)
6:14 (just to remember from where i have to continue, gtg sleep now)
Also, i know i'm a lil' late but i LOVE these tutorials!
love this series, saving my spot, 6:00!
22:19 hello great gnomecode sir
im using a custom rigged tower for this and it wont load the attack anim when it actually attacks it just continues the idle anim
if you know how to fix this please tell me
thank you
I had something similar but instead of it not playing the attack animation it would play the attack animation and not stop or go back to the idle animation and I saw what he did to fix it in the video and I did that but it still doesn't work
@@ThatDemonicGamer1 were u able to fix it?
This dude is like a teacher but a gamer one who helps you learn to make game ngl.
A code teacher
you are insane man your voice is so relaxing and you explain very well (im not english and sometimes i don't understand but with you i always understand) you are the best roblox studio channel on youtube !!!! continue like this we all love you !!
Amazing tutorial! Keep it up!
YOU'RE FIRST CZcamsR WHO TEACHES US HOW TO MAKE TD GAME! Also some ideas for next video: 1. Add admin commands like
!unit tank. 2. Add abilities for bosses like stunning towers for 2 seconds. 3. Tower that could spawn cars or tanks and that cars will kill zombies when touches them.
Yeah im 116+ lvl in tds im very love this game
@@thesad_lite7630 so uhh addons are gonna make that happen not the td tutorial so go in tower defense addons gnome code or some sort
Hello, Gnome! This series is fantastic so far! However, I'm having an issue and I was wondering if you could help me. I try to edit my code like the same way you do at 22:34 but my Tower still keeps doing the attack animation. I'm pretty sure I've done the entire script correctly, and I was wondering if you could help me.
Edited: I figured it out! Turns out, both my idle animation and attack animation were set to loop, but once I turned them both off, it broke the animations and made it so my tower held still. Turns out, if you let the idle animation loop, but not the attack animation, it works fine!
its either its not on action(iff its not then its gonna loop) or uve seeted it to loop(aka while making the animations u pressed the loop button and dint turn it off)
me too
@@subhfathesubmarine961 I'm not entirely sure what you mean by it not being on action, and after testing your loop button theory, it just makes the character hold completely still after finishing their animation.
@@subhfathesubmarine961 Nevermind, I figured it out!
bro mine was looping it was the same problem bc of you i could continue the series tysm
This is amazing ! Keep going i wanna see untill last episode!
saving my spot at 19:53 and btw nice work!
Tbh I LOVE this tower defense tutorial
1 Infinite yield possible on 'Workspace.Mobs.Basic:WaitForChild("Animation")' - Studio
17:14:28.481 Stack Begin - Studio
17:14:28.481 Script 'Players.JToH_SC.PlayerScripts.Animations', Line 3 - function setAnimation - Studio - Animations:3
Same
means a value is missing
the so long awaited video
Happy New Years! I can’t believe I actually integrated animations and facing enemy before this tutorial
Im still stuck in 2021.
@@GuiDuckz honestly, same
@@Ryan_Tse I just got into 2022.
@@GuiDuckz damn. Lucky
Hello i second. Your videos are nice and cool and great and good and awesome!!! Congrats with 50K subs!
Thanks again, all this is really helping me make my game, even thought it isn't a TDS game lol
good video love your series
Cool new video but I think my brain is so small for it:)(Happy new year!🎉)
Yooo, new video!! Thank you GnomeCode!
(Also First lol)
You Too cool And Happy New year
Amazing series!
ive seen you before
@@NacoPercyIsKool ok
WOW,I FOUND THIS FAST 33 SECONDS love your videos
For some reason the first wave of enemies get damaged for me but then the second wave nothing happens to them and it says it can find the humanoid of the enemy
Is there a way to make it so an item appears during animation and is hidden not in animation, EX: someone has a sword appear when they are attacking but in idle the sword is transparent
I worked on this for a long time, I can tell you how to make a working animation, you need to do everything the same on video, but only you must save the Save As animation on the character, and write it as new and its name, I say this to those who don’t it's very clear how to do it
HOLY THIS WORKS GREAT!!!!!!!!!!
i also have an error at 23:02, did the exact same line with animateTowerEvent:FireAllClients(newTower, "Attack), did it before target.Humanoid:TakeDamage(25), and it still loops the attack animation even if the zombies are out of range. is there a fix for this?
Maybe check the animation itself. You don't want the loop button to be toggled when you export it
When I try to do the attack animation it slows down the idle animation and never plays the attack animation (yes the attack animation is action and idle is idle, and also the tower is unanchored)
so im having this error that says "attempt to index nil with 'HumanoidRootPart' " thing so when the first tower is placed before, it wont attack the second wave... i dont know what to do
Man, can someone help me? I've tried looking through the comments and tried fixing it myself and neither worked. In the tower script, when I place the tower down, it just says "attempt to index nil as "Position" and the attack animation won't work?? My idle works fine and I've set them both the correct priority.
gnome code is there a better thing for the towers to face the enemies? i dont really want the towers to play their attacking animation when they havent faced the enemy yet
I don't know why, but my towers just stop attacking saying that there's no humanoid in my mobs even though there is. How would I fix this?
my tower rotates on the y axis, it makes them look up/down (their whole body which is weird), how do i make it so that it only rotates in x z axis or horizontally?
hey uh gnome code i have a problem and idk what it is, after i finished the mergeing tower scripts when i try to test it iff im in client mode then the scripts dissapear along with the other materials but iff im in server theyre there any ideas why?
edit: ive figured half of the equation, i dint have the tower in the replicated:towers:(tower) aka i dint have a tower to spawn and i accidently deleted it, but i stil dont understand why the scripts in serverscript service dont work.
edit 2:ive figured out they work but they dont show, but the problem is that i get a error with
Network Ownership API cannot be called on Anchored parts or parts welded to Anchored parts. - Server - Tower:46
Subhfa The Submarine
Anyone know why my character glitches through the floor when it tys to attack
Somthing to do with the BodyGyro but it dosen't stay still but if i anchor it the BodyGyro wont work so what should i do?
happy new year
Happy new year!
Hey GnomeCode, after killing an wave my towers just stop working they don't even run a FindNearestTarget function they just do nothing, why this could happen?
I need help on an error "LoadAnimation requires the Humanoid object (Zombie.Humanoid) to be a descendant of the game object" how do i fix this?
im getting a red underline by line 15 at tower.Position and it says that key 'Position' not found in table 'tower' and fix ?
what do i do at the facing enemy part when my tower is facing backwards when shooting
Guys since the body gyro is outdated,just delete all body gyros and make the code for facing in attack
Local look = lookat(newTower.HumanoidRootPart.position, (target.HumanoidRootPart.position.x, newTower.HumanoidRootPart.position.y, target.HumanoidRootPart.position.z)
NewTower.HumanoidRootPart.CFrame = look
so where am i suppost to put this script?
@@J4narC in tower module, attack function
lookat is underlined i have no idea what to do
(and im late)
@@ThatOneGu123 yep, you are 5 months late my guy
if you're having your animations clip, look for typos in the "Animations" script!
if the attack animation keeps playing even when you fix it make sure you turned off loop in animation itself then re-save and paste the ID
Easy to follow along and effective One request though Ailments (burn,boosts,ect)
Hey Gnome Code remember when u tell me to put capital M to replace with the not capital 1, on my serverscriptservice I put a Main folder and inside it its a Mods folder with the gear logo beside it and it still didn't work can you help me figure it out?
Hey gnomecode, I've got a video idea for this series. Adding custom health bars above the enemies. You should also make a currency needed to buy towers which you can get from killing enemies. Harder ones drop more. You should also make a base which you have to defend which also has a custom health bar and a screen gui. Keep up the good work and helpful videos.
he’s obviously going to teach us about the hp bar billboard, ingame cash, and all of that stuff, even tho it’s very simple cause it’s the fundamentals of a td game.
Fair enough
@@b_forbunnyyt1283 even above the enemies?
@@nooby5339well it’s very easy just search up a health bar tutorial and put it in the enemy
True
i cant believe you subbed this video when I was seeing the other parts, I discover your channel today and you make reallu cool videos, I like it
get a happy new 2022 and continue making this amazing content!
Happy new year mate. I shall see you next game night. Although it may be a problem getting the links seeing as I left discord
We'll see how it goes!
I got a problem with my animation from my tower
My animation from the tower stops before then playing the animation again.
Like it goes into the idle state and then into the attack animation over and over again and i dont know how to fix that.
Amazing Work GnomeCode One day You will have 1m subscribers before we all know it
Hey
2021 to 2022
Followed the tutorial, configuration folder is named Animations, Anim is named Idle, but still my scout stands and does absolutely nothing. I even get messages about completing the script, when its not moving. Any ideas that might help?