#Spinning part spazzes out randomly

1 messages · Page 1 of 1 (latest)

formal elm
#

I have a blade spinner for my TD, the blade spins in circles but sometimes for no reason just starts spazzing and doing verticle flips. Its quick and doesnt last longer than half a second, but its annoying that it exists

full radish
#

show code

formal elm
full radish
#

why not just use a loop to spin the blade whenever targets are in range

formal elm
#

thats what im doing

full radish
#

not a tween though

#

like it constatly updates the rotation is what i mean

formal elm
#

and how do i do that?

full radish
#

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)
formal elm
#

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

full radish
#

well you could just set the attribute to true and then to false when the cooldown starts

#

and then back to true

formal elm
#

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?

full radish
#

that would be an unnecessary but working solution i'd assume

formal elm
#

i think it might be better with animation because of the towers cooldowns

#

the blade speed needs to match it

full radish
#

you can try to see if it bugs like the current one

#

try the animation i mean

formal elm
#

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?

full radish
#

if you play animations client-side everyone is going to be able to see them

formal elm
full radish
#

have you rigged the tower up properly

formal elm
#

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

full radish
#

you're loading the animation every loop cycle?

#

and you're also playing it every cycle

formal elm
#

yes

full radish
#

you should make a variable to see if it's playing right now

#

because currently you're just re-playing it

formal elm
#

the blade doesnt even move, thats the problem

full radish
#
local playingAnimation = false

-- in loop
if not playingAnimation then
  playingAnimation = true
  bladeSpin:Play()
end
#

try this though

formal elm
#

okay

full radish
#

set it to false when there are no targets

formal elm
#

where abouts should i put this?

full radish
#

put local playingAnimation outside of the loop

#

and the part that i commented --in loop you put instead of this play line

formal elm
#

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

full radish
#

then there's something wrong with the animation

#

you need to set the playingAnimation variable back to false when there are no targets

formal elm
#

oh shit yea

ruby garnetBOT
#

studio** You are now Level 10! **studio

formal elm
#

couldnt i just do this?

full radish
#

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
formal elm
full radish
#

no not that either

formal elm
#

okay wait wait

full radish
#

that just sets it back immediately aswell

formal elm
#

why would it

formal elm
#

thats what you put?

full radish
#

no

#

i didn't

formal elm
#

ohh its under found targets

#

i see

#

like this?

full radish
#

no

#

just put else not elseif

formal elm
#

im confused

full radish
#

okay so

#

after the else

full radish
#

no

#

the if statement is a separate thing

formal elm
#

whats the difference between elseif and else if?

full radish
#

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

formal elm
#

yes but it takes the same requirements to reach the line no?

full radish
#

?

formal elm
#

ill change it but i genuinely dont think it makes a difference

full radish
full radish
#

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

formal elm
#

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

full radish
#

i just check if its playing to not change the variable every time

full radish
formal elm
full radish
#

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

formal elm
#

almost 100%, ill go back and double check

full radish
#

also you should probably use an AnimationController instead of humanoid.animator for the tower

formal elm
#

i cant

full radish
#

alright

formal elm
#

i tried using an animationcontroller yesterday

#

it said it was depricated

full radish
#

i see

#

that's fine then

#

humanoid.animator works as well

formal elm
#

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

full radish
#

the rigging is strange then

formal elm
#

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?

full radish
#

🤷

formal elm
#

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

full radish
#

okay so

#

i have a solution

#

probably will work

formal elm
#

what might that be

full radish
#

can you copy the script and paste it

#

in here

formal elm
#

sure

#

big ass script

full radish
#

uhh what about just that part that you sent in the beginning

formal elm
#

yea thought so

full radish
#

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

formal elm
#

ill try that in a sec, but i just found out that the humanoid was interfering with the animation

full radish
#

this should continoueuseusly rotate the blade until it's stopped

formal elm
#

im gonna test the animation controller again, maybe its not depricated on some things?

full radish
#

alright

formal elm
#

PROGRES

#

PROGRESS

#

PROGRESS

#

the blade spun ONCE

#

only one time

full radish
#

okayy

formal elm
#

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?

full radish
#

i mean you can send me it and i can try

formal elm
full radish
#

oh the solution is easier than expected

#

okay so you need to reupload the animation

#

but make it looped

formal elm
#

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

full radish
formal elm
#

okay cheers

full radish
#

first of all reupload the animation but make it looped in the animation editor

#

and then replace the else with this

formal elm
#

how tf i do that..

full radish
#

well just add that :Stop() line

full radish
formal elm
#

yes

#

i dont animate bro

#

have u seen the animation

full radish
#

no

#

and then reupload it (overwrite the old one)

formal elm
#

alright

#

done

#

now what

full radish
formal elm
#

done

full radish
#

now if you test the game it should work fine

formal elm
#

so

#

its spinning

#

and it wont stop spinning

full radish
#

🤔

formal elm
#

double check it looks good

full radish
#

is that function running frequently

#

okay can you give me the whole script again

formal elm
#

which runs every hit cooldown

#

for example, the blade spinner will run 2 times per second, it has a 0.5s cooldown

full radish
#

i see

#

so can i have the whole script

formal elm
full radish
#

thanks

formal elm
#

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

full radish
#

it does run it's just that you load the animation everytime i t runs

formal elm
#

yes

#

just said that

full radish
#

blah blah blahh you can remove the if statemnt whateverr

formal elm
#

which one

#

why dont i just do another check?

#

im smart

#

wait

#

and the local for that is outside the loop

full radish
#

yeah but animationloaded is global

#

like

#

every time a tower gets placed down and starts spinning

#

it will override it

#

give me a second

formal elm
#

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

full radish
#

🤔 good idea but do you mind trying my solution

formal elm
#

ofc ofc

full radish
#

just replace your whole script with this

#

except remove that hello world on the first line my bad

formal elm
#

besides my config is messy for the towers anyways, look at this shit

full radish
#

i don't think that's messy

formal elm
#

ahhh

#

you did it with attributes

full radish
#

yes

formal elm
full radish
#

aswell as a table

formal elm
#

okay well

full radish
#

which i don't know if it was necessary or not but oh well

formal elm
#

talk me through it as its so impossible for me to read those txt files

full radish
#

you want me to explain how i did it?

#

or how to replace it?

formal elm
#

just explain

#

and ill do it

full radish
#

you can download that txt, ctrl + a inside it and then paste it into your script

formal elm
#

like a youtube tutorial with only subtitles

formal elm
#

not saying you would do that, your chill

#

but the fear

#

no can do

full radish
#

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

formal elm
#

holy fart bubble 😭

#

its a good script

#

but i only needed to check if it was loaded 😭

full radish
#

except wait

#

i forgot to add some stuff

#

give me a second

#

not at that part

formal elm
#

BROOO

full radish
#

that part is finished

formal elm
#

can we just use a boolean

#

holy

full radish
#

no it won't work

formal elm
#

okay i trust

#

im gonna start writing this

full radish
#

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

formal elm
#

but your showing me to put it at --ATTACKFIREAOE

full radish
#

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

formal elm
#

no i meant

#

look

full radish
#

yeah i told you to move it

#

up to line 87

formal elm
#

okay

#

right

#

so

#

start again

#

from here

full radish
#

okay so

#

remove the playing animation variable because it's useless now

full radish
formal elm
#

done

full radish
#

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

formal elm
#

oaky

#

circle bit added

#

is that it?

full radish
#

and remove the original bladespin variable

#

if you still have it

formal elm
#

done

full radish
#

okay

formal elm
#

testing

full radish
#

i think that's everything

#

🙏

full radish
#

hmm

formal elm
#

bru

#

you told me to remove the first one but not this

full radish
#

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

formal elm
#

bro

#

okay

#

okay

full radish
#

local playingAnimation = tower:GetAttribute("playingAnimation")

formal elm
#

wait

#

so iv added 2 things

full radish
#

im sorry man i don't always make stuff first try

formal elm
#

this

#

this all i added

formal elm
full radish
formal elm
#

so have i added everything

full radish
#

and before this part in the code

#

add this

#
local playingAnimation = tower:GetAttribute("playingAnimation")
formal elm
full radish
formal elm
full radish
#

yes

formal elm
#

the blade isnt spinning

full radish
#

that should now hopefully be everything

formal elm
#

is this the problem

formal elm
full radish
#

yes sorry for not explaining it better

formal elm
#

we are telling it to stop if its playing when targets are more than 0

full radish
#

put Play instead of Stop

#

and show me the rest of the #foundtargets thing

formal elm
#

was gonna say 😭

full radish
#

after the else

formal elm
#

ignore the cheese

#

i got too many prints, needed a new keyword

full radish
#

alright that's good

formal elm
#

hes not spinnin

full radish
#

oh

#

okay so

full radish
formal elm
#

btw

#

we didnt get cheese2

#

that means that it isnt finding a playinganimation

full radish
#

replace playing animation = false with

tower:SetAttribute("playingAnimation", false)
#

i know

#

and after you did that

full radish
#

replace

tower:SetAttribute("playingAnimation", false)

with

tower:SetAttribute("playingAnimation", true)
formal elm
#

done

full radish
#

show the function

formal elm
#

the whole thing?

full radish
#

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

formal elm
#

no spin

full radish
#

so basically swap the booleans around

#

can you show the code

formal elm
#

uhhhh

#

what if we do my boolean idea?

#

this is complex

full radish
#

show code first then you can try

full radish
#

okay okay so

#

in the line below bladespin

#

change

#

GetAttribute

#

to SetAttribute

formal elm
#

which bladespin

#

theres like 4

full radish
#

bladespin:Play()

#

so like here

#

yeah that part

formal elm
#

no spin

full radish
#

replace GetAttribute with SetAttribute

formal elm
#

i did

#

no spin

full radish
#

do you mind showing code last time

formal elm
#

no cheese2 either

full radish
#

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"

formal elm
#

i added 4 prints to test too

#

we got 1 and 2

#

which is

#

nil with play

full radish
#

okay i give up on my idea

#

you can try your boolean thing

formal elm
#

okay

#

gimme 10 mins

full radish
#

i also personally have to go

#

so that's that

formal elm
#

alg bro, ill update you if you ever come back

full radish
#

i'll come back in roughly 12-14 hours

full radish
formal elm
#

alg bro, ill leave you the update message here for my progress on this dogshit

full radish
#

alright

#

cya and good luck

formal elm
#

cheers for the help bro

formal elm
#

@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)