Skip to content

S #5

@h1xen-lol

Description

@h1xen-lol

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local SummonStandEvent = ReplicatedStorage:WaitForChild("SummonStandEvent")
local StandAttackEvent = ReplicatedStorage:WaitForChild("StandAttackEvent")
local StandStrongAttackEvent = ReplicatedStorage:WaitForChild("StandStrongAttackEvent")
local Workspace = game:GetService("Workspace")
local StandTemplate = ServerStorage:FindFirstChild("Stand")
local Stand2Template = ServerStorage:FindFirstChild("Stand2")
local Stand3Template = ServerStorage:FindFirstChild("Stand3")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local StandAnimation = require(game:GetService("ServerScriptService"):FindFirstChild("StandAnimation"))

local NORMAL_ATTACK_ANIMATION_ID = "rbxassetid://94891482400381"
local STRONG_ATTACK_ANIMATION_ID = "rbxassetid://94891482400381"

local playerStands = {}
local followConnections = {}

local downOffset = Vector3.new(0, 1, 0)

local function removeStand(player)
local stand = playerStands[player]
if stand and stand.Parent then
stand:Destroy()
end
playerStands[player] = nil
if followConnections[player] then
followConnections[player]:Disconnect()
followConnections[player] = nil
end
end

local function positionStand(character, stand)
local root = character:FindFirstChild("HumanoidRootPart")
if root then
local backOffset = root.CFrame.LookVector * -2
local leftOffset = root.CFrame.RightVector * -2
local offset = backOffset + leftOffset + downOffset
stand:PivotTo(root.CFrame + offset)
end
end

local function followStand(player)
local character = player.Character
local stand = playerStands[player]
if not character or not stand then return end

if followConnections[player] then
    followConnections[player]:Disconnect()
end

followConnections[player] = RunService.Heartbeat:Connect(function()
    if not character.Parent or not stand.Parent then
        if followConnections[player] then
            followConnections[player]:Disconnect()
            followConnections[player] = nil
        end
        return
    end
    positionStand(character, stand)
end

end

local function ensureAnimator(stand)
local humanoid = stand:FindFirstChildOfClass("Humanoid")
if humanoid then
local animator = humanoid:FindFirstChildOfClass("Animator")
if not animator then
Instance.new("Animator", humanoid)
end
end
end

local function summonStand(player)
local character = player.Character
if not character then
return
end
if not StandTemplate then
return
end

removeStand(player)

local stand = StandTemplate:Clone()
stand.Parent = Workspace
ensureAnimator(stand)
playerStands[player] = stand

positionStand(character, stand)

followStand(player)

local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
    humanoid.Died:Connect(function()
        removeStand(player)
    end)
end

end

SummonStandEvent.OnServerEvent:Connect(function(player)
if playerStands[player] then
removeStand(player)
else
summonStand(player)
end
end)

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
removeStand(player)
end)
end)

Players.PlayerRemoving:Connect(function(player)
removeStand(player)
end

local function swapStand(player, newTemplate)
local oldStand = playerStands[player]
if not oldStand or not newTemplate then return oldStand end
local character = player.Character
local oldCFrame = oldStand:GetPivot()
oldStand:Destroy()
local newStand = newTemplate:Clone()
newStand.Parent = Workspace
ensureAnimator(newStand)
newStand:PivotTo(oldCFrame)
playerStands[player] = newStand
return newStand
end

local function findNearestTarget(character)
local root = character:FindFirstChild("HumanoidRootPart")
if not root then return nil end
local nearest = nil
local nearestDist = math.huge
for _, obj in Workspace:GetChildren() do
if obj:IsA("Model") and obj ~= character then
local humanoid = obj:FindFirstChildOfClass("Humanoid")
local hrp = obj:FindFirstChild("HumanoidRootPart")
if humanoid and hrp and humanoid.Health > 0 then
local dist = (hrp.Position - root.Position).Magnitude
if dist < 8 and dist < nearestDist then
nearest = humanoid
nearestDist = dist
end
end
end
end
return nearest
end

-- Multi-hit attack (E) - 10 раз по 5 урона
StandAttackEvent.OnServerEvent:Connect(function(player)
local stand = playerStands[player]
local character = player.Character
if not stand or not character then
return
end

if followConnections[player] then
    followConnections[player]:Disconnect()
    followConnections[player] = nil
end

local root = character:FindFirstChild("HumanoidRootPart")
if not root then
    return
end

local forwardOffset = root.CFrame.LookVector * 4
local standCFrame = root.CFrame + forwardOffset + downOffset
stand:PivotTo(standCFrame)

local attackTrack = StandAnimation.PlayAnimation(stand, NORMAL_ATTACK_ANIMATION_ID)

-- 10 ударов по 5 урона
for i = 1, 10 do
    local targetHumanoid = findNearestTarget(character)
    if i % 2 == 1 and Stand2Template then
        stand = swapStand(player, Stand2Template)
    elseif i % 2 == 0 and Stand3Template then
        stand = swapStand(player, Stand3Template)
    end
    
    -- Наносим урон 5
    if targetHumanoid and targetHumanoid.Health > 0 then
        targetHumanoid.Health = targetHumanoid.Health - 5
    end
    
    -- Перемещаем стенд к цели
    if targetHumanoid and targetHumanoid.Parent then
        local targetHRP = targetHumanoid.Parent:FindFirstChild("HumanoidRootPart")
        if targetHRP then
            stand:PivotTo(targetHRP.CFrame)
        end
    end
    task.wait(0.15)
end

if attackTrack then
    attackTrack:Stop()
end

if StandTemplate then
    stand = swapStand(player, StandTemplate)
end

positionStand(character, stand)
followStand(player)

end)

-- Strong attack (R)
StandStrongAttackEvent.OnServerEvent:Connect(function(player)
local stand = playerStands[player]
local character = player.Character
if not stand or not character then
return
end

if followConnections[player] then
    followConnections[player]:Disconnect()
    followConnections[player] = nil
end

local root = character:FindFirstChild("HumanoidRootPart")
if not root then
    return
end

local forwardOffset = root.CFrame.LookVector * 4
local standCFrame = root.CFrame + forwardOffset + downOffset
stand:PivotTo(standCFrame)

local strongTrack = StandAnimation.PlayAnimation(stand, STRONG_ATTACK_ANIMATION_ID)

local targetHumanoid = findNearestTarget(character)

if Stand2Template then
    stand = swapStand(player, Stand2Template)
    if targetHumanoid and targetHumanoid.Health > 0 then
        targetHumanoid.Health = targetHumanoid.Health - 15
    end
    if targetHumanoid and targetHumanoid.Parent then
        local targetHRP = targetHumanoid.Parent:FindFirstChild("HumanoidRootPart")
        if targetHRP then
            stand:PivotTo(targetHRP.CFrame)
        end
    end
    task.wait(0.07)
end

if Stand3Template then
    stand = swapStand(player, Stand3Template)
    if targetHumanoid and targetHumanoid.Health > 0 then
        targetHumanoid.Health = targetHumanoid.Health - 15
    end
    if targetHumanoid and targetHumanoid.Parent then
        local targetHRP = targetHumanoid.Parent:FindFirstChild("HumanoidRootPart")
        if targetHRP then
            stand:PivotTo(targetHRP.CFrame)
        end
    end
    task.wait(0.07)
end

task.wait(0.3)
if strongTrack then
    strongTrack:Stop()
end

if StandTemplate then
    stand = swapStand(player, StandTemplate)
end

positionStand(character, stand)
followStand(player)

end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions