#Spinning part spazzes out randomly
1 messages · Page 1 of 1 (latest)
show code
why not just use a loop to spin the blade whenever targets are in range
thats what im doing
and how do i do that?
you can add an attribute to the blade that gets turned on/off whenever enemies are in range
and add an event that picks up on when the attribute gets changed to begin the spinning
a while loop that breaks when the attribute is set to false again
or you can do this
game.RunService.HeartBeat:Connect(function()
if not tower:GetAttribute("spinning") then return end
tower.Blades.CFrame *= CFrame.Angles(0, math.rad(1), 0)
end)
this would be hard to implement as the blades spin at the cooldown rate which is set on the tower, and it would update when the tower is upgraded
well you could just set the attribute to true and then to false when the cooldown starts
and then back to true
do you think this could work if i made an animation of it doing a 360 and make it run that animation until enemies are not in range?
that would be an unnecessary but working solution i'd assume
i think it might be better with animation because of the towers cooldowns
the blade speed needs to match it
yea, let me give it a go and then ill get back to you
@full radish Just a quick question, if im playing an animation on the client side for a tower, will it show to all players?
yes
if you play animations client-side everyone is going to be able to see them
ah, well for some reason this animation isnt working
have you rigged the tower up properly
yes
i event made the animation, exported and loaded it in the code
the print above bladeSpin:Play() will print ever time an enemy is in range, but the animation will never play
you're loading the animation every loop cycle?
and you're also playing it every cycle
yes
you should make a variable to see if it's playing right now
because currently you're just re-playing it
the blade doesnt even move, thats the problem
local playingAnimation = false
-- in loop
if not playingAnimation then
playingAnimation = true
bladeSpin:Play()
end
try this though
okay
set it to false when there are no targets
where abouts should i put this?
put local playingAnimation outside of the loop
and the part that i commented --in loop you put instead of this play line
and the first line is outside loop
lemme test
okay so
It now only prints "Play" once
and didnt print it again for the entire wave
then there's something wrong with the animation
you need to set the playingAnimation variable back to false when there are no targets
oh shit yea
** You are now Level 10! **
couldnt i just do this?
no that'll set it back to false immediately
you should do this
if #foundTargets > 0 then
-- the stuff you have
else
if playingAnimation then
playingAnimation = false
end
end
no not that either
that just sets it back immediately aswell
why would it
do this thing
thats what you put?
im confused
yours is an elseif
whats the difference between elseif and else if?
else if is different because the if is on another line meaning it's a whole complete check/statement
this is how it should look like
yes but it takes the same requirements to reach the line no?
?
ill change it but i genuinely dont think it makes a difference
if the number of targets is above zero it starts the animation and does'nt stop it
and if the number is the opposite, aka zero or below, it will stop it
it does
if you put
elseif playingAnimation == false
it will only do that elseif if playingAnimation is false
which it never gets to be after it gets set to true
im confused, it only gets to the else if there are more than 0 targets
the if checks if the animation is playing
of which is does anyway
so it doesnt change anything
anyways
i changed it to the if below the line
whats next
i just check if its playing to not change the variable every time
can you show me your script
now the core part should be fine but the animation still has an issue
are you 100% certain that you set up the tower rig completely fine and that the animator is also set up fine
almost 100%, ill go back and double check
also you should probably use an AnimationController instead of humanoid.animator for the tower
i cant
alright
its only allowed on humanoids now or something
the bishop looks okay so far
1 sec
huh
so for some reason the entire blad is affecting the rotation of the bishop
the rigging is strange then
if i disable the motor, then rotate the blade back and then re enable the motor, it just forces the blade back to how it was again
and now the animation is showing no movement when before it was
weird
seems like the blade is welded when its not or somethin
i deleted the motor, just replacing it
maybe itll work?
🤷
so, the blade requires a motor to be rigged, but doesnt move in the animator when it has one??
this is fucked
im just gonna delete the humanoid and try again
what might that be
uhh what about just that part that you sent in the beginning
i just replaced this part honestly
if not playingAnimation then
playingAnimation = true
coroutine.wrap(function()
while playingAnimation do
blade.CFrame *= CFrame.Angles(0, math.rad(90), 0)
task.wait()
end
end)()
print("Play")
end
whoops
there
ill try that in a sec, but i just found out that the humanoid was interfering with the animation
this should continoueuseusly rotate the blade until it's stopped
im gonna test the animation controller again, maybe its not depricated on some things?
alright
okayy
right, im gonna send you the updated script, are you able to throw in some magic and make it spin continuously until theres no enemies?
don't mind this part
i mean you can send me it and i can try
cheers
oh the solution is easier than expected
okay so you need to reupload the animation
but make it looped
also, as a second thing if possible, the animation is 1 second long, and i need the animation to match the length of towerCooldown which is a variable already
we'll get to that in a second
okay cheers
first of all reupload the animation but make it looped in the animation editor
and then replace the else with this
how tf i do that..
well just add that :Stop() line
are you using robloxs default animator
add that bladeSpin:Stop() line llike in here
done
now if you test the game it should work fine
🤔
the function is called here
which runs every hit cooldown
for example, the blade spinner will run 2 times per second, it has a 0.5s cooldown
thanks
i did some print testing
so, when there is no targets, it prints cheese1, and when there is no targets AND the animation is playing it prints cheese2
BUT
the bladeSpin:Stop() doesnt run
ahhhhhhh
same issue we spoke about earlier
its loading it every time
it does run it's just that you load the animation everytime i t runs
blah blah blahh you can remove the if statemnt whateverr
which one
why dont i just do another check?
im smart
wait
and the local for that is outside the loop
yeah but animationloaded is global
like
every time a tower gets placed down and starts spinning
it will override it
give me a second
true your right
it needs to load it per tower placed
well
bishop placed
WAIT
i might be smart
what if i add a boolean value to the bishops and have it set to false, and then when the script runs it will check if the boolean is false and if it is then it will load the animation and change the boolean on that tower to true
so then it should be tower specific
🤔 good idea but do you mind trying my solution
ofc ofc
just replace your whole script with this
except remove that hello world on the first line my bad
i don't think that's messy
yes
this is my least messy tower
aswell as a table
okay well
which i don't know if it was necessary or not but oh well
talk me through it as its so impossible for me to read those txt files
you can download that txt, ctrl + a inside it and then paste it into your script
like a youtube tutorial with only subtitles
true, but i have huge fears of that, one time a guy tried to stunt me by putting shit in my script
not saying you would do that, your chill
but the fear
no can do
i understand
👀
anyway
at these lines i changed some code
well added
local loadedAnimations = {}
-- FIRE PROJECTILE
animateTowerEvent.OnClientEvent:Connect(function(tower, animationName, target, player)
if not loadedAnimations[tower] then
loadedAnimations[tower] = tower.AnimationController.Animator:LoadAnimation(ReplicatedStorage.TowerAnimations.BladeSpin)
tower:GetAttributeChangedSignal("Parent"):Once(function()
loadedAnimations[tower] = nil
end)
end
it adds the loaded animation to the table which contains all the tower animations
BROOO
that part is finished
no it won't work
you can just copy and paste it
put local loadedAnimations at line 87
instead of whatever line i had it before
and add this in the attack aoe function thing
why is the loaded animations on this one at --FIRE PROJECTILE
but your showing me to put it at --ATTACKFIREAOE
well because loaded animations is a variable which is below the function
so the function can't access the variable
which i didn't remember while writing that
this
look 2nd line
and addthe circled thing into the aoe function
done
according to my calculations it should work fine when testing
if you also changed that uhh
event part
i'm hoping this works because i can't test it
done
okay
testing
hmm
oh yeah my bad
you replace that one
with this
if playingAnimation then
bladeSpin:Stop()
tower:GetAttribute("playingAnimation", false)
end
and
adn
at line line 130 or something add this
local playingAnimation = tower:GetAttribute("playingAnimation")
im sorry man i don't always make stuff first try
dont be sorry
replace that
so have i added everything
with this
and before this part in the code
add this
local playingAnimation = tower:GetAttribute("playingAnimation")
before the local bladespin part add this line
yes
the blade isnt spinning
that should now hopefully be everything
is this the problem
yes sorry for not explaining it better
we are telling it to stop if its playing when targets are more than 0
was gonna say 😭
after the else
hes not spinnin
in that part
replace playing animation = false with
tower:SetAttribute("playingAnimation", false)
i know
and after you did that
in this part
replace
tower:SetAttribute("playingAnimation", false)
with
tower:SetAttribute("playingAnimation", true)
done
show the function
yeah that
uhh okay so
you see the line 2 lines after cheese2
replace the true with false
so it sets it to false
and in the line below bladespin:Play() set it to true
replace false with true
no spin
show code first then you can try
no spin
replace GetAttribute with SetAttribute
do you mind showing code last time
last modification before you can try ytour boolean idfea
if playingAnimation then
bladeSpin:Play()
tower:SetAttribute("PlayingAnimation", true)
end
in this part right
instead of"if playingAnimation" do "if not playingAnimation"
alg bro, ill update you if you ever come back
i'll come back in roughly 12-14 hours
/next day
alg bro, ill leave you the update message here for my progress on this dogshit
cheers for the help bro
@full radish
For when your on next, fixed it
Bool value updates for all towers fluently. And for the cooldown influencing the speed of the blade i just usedthe the formula/code: bladeSpin:AdjustSpeed(1 / towerCooldown)
