#script advice

1 messages · Page 1 of 1 (latest)

coarse snow
#

made this script for an npc so its attacks don't happen at the same time
its tweens kept interrupting eachother so after a while i came up with this and it seems to work but tell me if you see any issues

    task.wait(1)
    game:GetService('RunService').Heartbeat:wait()
    local r = nearestPlayer()
    if Order == 1 and CD1 == false then
        CD1 = true
        local Randomlook = math.random(5,8)
        CurrentlyLooking = true
        print("function1")
        startattack()
        task.wait(Randomlook)
        CD1 = false
        Order = Order + 1
    elseif Order == 2 and CD1 == false then
        CD1 = true
        task.wait(1)
        Attack = true
        CurrentlyLooking = true
        print("function2")
        local Randomlook = math.random(1,4)
        PlayerLookAt()
        task.wait(Randomlook)
        CD1 = false
        CurrentlyLooking = false
        Order = Order - 1
    end
end```
undone quiver
#

why are you additionally waiting a heartbeat?

#

also the script can be improved

coarse snow
undone quiver
#

what are you talking about

coarse snow
# undone quiver what are you talking about

one of the attacks requires the muffins jumping into the air and dropping back down, the other tween would interrupt this leaving the muffin in the air and it would keep interrupting, or the same function would fire 200 times so i put a bunch of values and debounces to prevent it

#

im just saying i rushed it

undone quiver
#

without playing a 2nd tween

coarse snow
undone quiver
#

yeah but what's the point in a 2nd tween unless you want for both tweens to differ

coarse snow
undone quiver
#

okay fair enough

coarse snow
#

also they don't fight its the other tween that fights with the other 2

undone quiver
#

but the way you change the order can be significantly improved

#

instead of adding/removing you can just set it to 1 or 2

#
if order == 1 then
  order = 2
else
  order = 1
end
#

or you can use a boolean

coarse snow
#

yea you're right i was just planning to add more attacks in the future and i wanted the number to be added to order to be random