Skip to content

Riblox #4

@h1xen-lol

Description

@h1xen-lol

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SummonStandEvent = ReplicatedStorage:WaitForChild("SummonStandEvent")
local StandAttackEvent = ReplicatedStorage:WaitForChild("StandAttackEvent")
local StandStrongAttackEvent = ReplicatedStorage:WaitForChild("StandStrongAttackEvent")
local Workspace = game:GetService("Workspace")
local StandTemplate = Workspace:FindFirstChild("Stand")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local NORMAL_ATTACK_ANIMATION_ID = "rbxassetid://12345678"
local STRONG_ATTACK_ANIMATION_ID = "rbxassetid://87654321"

local playerStands = {}
local followConnections = {}

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 * -3
local leftOffset = root.CFrame.RightVector * -2
local offset = backOffset + leftOffset
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 summonStand(player)
local character = player.Character
if not character or not StandTemplate then return end

removeStand(player)

local stand = StandTemplate:Clone()
stand.Parent = Workspace
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, shouldShow)
if shouldShow then
summonStand(player)
else
removeStand(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 findNearestTarget(stand, player)
local standPos = stand:GetPivot().Position
local nearestTarget = nil
local nearestDist = 8

local npc = Workspace:FindFirstChild("npc")
if npc and npc:FindFirstChildOfClass("Humanoid") then
    local npcRoot = npc:FindFirstChild("HumanoidRootPart")
    if npcRoot then
        local dist = (npcRoot.Position - standPos).Magnitude
        if dist < nearestDist then
            nearestTarget = npc
            nearestDist = dist
        end
    end
end

for _, otherPlayer in Players:GetPlayers() do
    if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChildOfClass("Humanoid") then
        local otherRoot = otherPlayer.Character:FindFirstChild("HumanoidRootPart")
        if otherRoot then
            local dist = (otherRoot.Position - standPos).Magnitude
            if dist < nearestDist then
                nearestTarget = otherPlayer.Character
                nearestDist = dist
            end
        end
    end
end
return nearestTarget

end

local function playStandAnimation(stand, animationId)
local humanoid = stand:FindFirstChildOfClass("Humanoid")
if humanoid then
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local track = animator:LoadAnimation(animation)
track:Play()
return track
end
end
return nil
end

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
stand:PivotTo(standCFrame)

local attackTrack = playStandAnimation(stand, NORMAL_ATTACK_ANIMATION_ID)
for i = 1, 10 do
    local target = findNearestTarget(stand, player)
    if target then
        local humanoid = target:FindFirstChildOfClass("Humanoid")
        if humanoid and humanoid.Health > 0 then
            humanoid.Health = humanoid.Health - 5
        end
    end
    task.wait(0.15)
end
if attackTrack then
    attackTrack:Stop()
end

positionStand(character, stand)
followStand(player)

end)

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
stand:PivotTo(standCFrame)

local strongTrack = playStandAnimation(stand, STRONG_ATTACK_ANIMATION_ID)
local target = findNearestTarget(stand, player)
if target then
    local humanoid = target:FindFirstChildOfClass("Humanoid")
    if humanoid and humanoid.Health > 0 then
        humanoid.Health = humanoid.Health - 15
    end
end
task.wait(0.3)
if strongTrack then
    strongTrack:Stop()
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