#(Solved) Tower Defense game Attack Animation

44 messages · Page 1 of 1 (latest)

shy parcel
#

what line is the error

carmine horizon
void halo
karmic oyster
drifting orbitBOT
#

studio** You are now Level 2! **studio

karmic oyster
#
local PhysicServie = game:GetService("PhysicsService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local events = ReplicatedStorage:WaitForChild("Events")
local SpawnTowerEvent = events:WaitForChild("SpawnTower")
local AnimateTowerEvent = events:WaitForChild("AnimateTower")



local tower = {}

function FindNearestTarget(newTower)
    local maxDistance = 20
    local nearestTarget = nil

    for i, target in ipairs(workspace.Mobs:GetChildren()) do
        local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
        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(25)
    end
    wait(1)
    AnimateTowerEvent:FireAllClients(newTower, "Attack")
    
    tower.Attack(newTower)
end

function tower.Spawn(player, name, cframe)
    local TowerExist = ReplicatedStorage.Towers:FindFirstChild(name)
    
    if TowerExist then
            local newTower = TowerExist:Clone()
        newTower.HumanoidRootPart.CFrame = cframe
        newTower.Parent = workspace.Towers
        newTower.HumanoidRootPart:SetNetworkOwner(nil)
            
            
            
            
        for i, object in ipairs(newTower:GetDescendants()) do
                if object:IsA("Part") then
                    object.CollisionGroup = "Tower"
                end
            end
coroutine.wrap(tower.Attack)(newTower)
    else    
        warn("Requested tower does not exist", name)
        
    end
end

SpawnTowerEvent.OnServerEvent:Connect(tower.Spawn)

return tower
karmic oyster
#
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local events = ReplicatedStorage:WaitForChild("Events")
local AnimateTowerEvent = events:WaitForChild("AnimateTower")


local function SetAnimation(object, animName)
    local humanoid = object:WaitForChild("Humanoid")
    local animationsFolder = object:WaitForChild("Animations")

    if humanoid and animationsFolder then
        local AnimationObject = animationsFolder:WaitForChild(animName)

        if AnimationObject then
            local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
            local AnimationTrack = animator:LoadAnimation(AnimationObject)
            return AnimationTrack

        end
    end
end

local function PlayAnimation(object, animName)
    local AnimationTrack = SetAnimation(object, animName)
    if AnimationTrack then
        if animName == "Idle" then
             AnimationTrack:Play(1, 1, 0.15)
        end
        if animName ~= "Idle" then
            AnimationTrack:Play()
        end
    else
        warn("Animation Track Doesnt Exist")
    end

end




workspace.Mobs.ChildAdded:Connect(function(object)
    PlayAnimation(object, "Walk")
end)

workspace.Towers.ChildAdded:Connect(function(object)
    PlayAnimation(object, "Idle")
end)

AnimateTowerEvent.OnClientEvent:Connect(function(tower, animName)
    PlayAnimation(tower, animName)
end)
#

Animation script

#

it can find idle animation

knotty dagger
#

i would like to thank you

#

its thanks to you that now im really mad at people that doesnt format their code

#

so i coded i python script that will format it for you

#

and make it a discord bot

#

as you can see it works pretty well

empty zinc
knotty dagger
#

now i just need to select the code snippets when it detects lines with lua, then delete your fucking ugly code and replace it by a real code

knotty dagger
empty zinc
#

What feature

knotty dagger
#

do you enjoy seing unformatted code or dont you care ?

#

if you dont care, are you a dev ?

empty zinc
#

What u mean by unformatted code

knotty dagger
#

this

empty zinc
#

Ok its shit

knotty dagger
knotty dagger
# empty zinc Ok its shit

yes so now ill dev a bot since im lazy to not be able to help people that doesnt format their code

#

lol

karmic oyster
knotty dagger
#

im not actually mad at you

#

everyone does mistake, and im sorry if you have been offended it was not my intention

knotty dagger
#

cause you had the perfect code for me to test

karmic oyster
#

np

karmic oyster
#

@knotty dagger so do you have any idea how to fix it?

knotty dagger
#

tbh i suck at animation scripting :/

#

im really good at deep code

knotty dagger
empty zinc
#

Donne bot

#

🙂

karmic oyster
#

somehow it starded working i have no clue how i didnt changed anything lmao

#

(Solved) Tower Defense game Attack Animation