So,i’m trying to make 4 different abilties,so,there is a function for every of them,i’ve encountered a problem with the echo summon function,the bug is attempt to index nil with parent,it probaby seems,that the script can’t find the character?i don’t really know and i’m aware there’re tons of other errors in different functions.Anyways,here is the module script:
local EchoesAbilities = {}
local Players = game:GetService("Players")
local MAX_ECHOES = 3
local ECHO_DURATION = 5
local ECHO_FRENZY_DURATION = 3
local ECHO_DISRUPT_DURATION = 2
local ECHO_DISRUPT_RANGE = 10
local cooldowns = {
EchoSummon = 10,
EchoMove = 5,
EchoFrenzy = 15,
EchoDisrupt = 12
}
local activeEchoes = {}
function EchoesAbilities:EchoSummon(player)
if not player then
warn("EchoSummon: player is nil")
return
end
if not activeEchoes[player] then
activeEchoes[player] = {}
end
if #activeEchoes[player] < MAX_ECHOES then
local character = player.Character or player.CharacterAdded:Wait()
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local clone = character:Clone()
clone.Parent = workspace
clone:SetPrimaryPartCFrame(humanoidRootPart.CFrame)
table.insert(activeEchoes[player], clone)
task.delay(ECHO_DURATION, function()
for i = #activeEchoes[player], 1, -1 do
local echo = activeEchoes[player][i]
if echo then
echo:Destroy()
table.remove(activeEchoes[player], i)
end
end
end)
else
warn("EchoSummon: Character does not have a HumanoidRootPart")
end
else
warn("EchoSummon: Character is nil")
end
end
end
function EchoesAbilities:EchoMove(player)
if activeEchoes[player] and #activeEchoes[player] > 0 then
local character = player.Character
if character and character.PrimaryPart then
local echo = activeEchoes[player][1]
if echo and echo.PrimaryPart then
local newPosition = character:GetPrimaryPartCFrame() * CFrame.new(5, 0, 0)
echo:SetPrimaryPartCFrame(newPosition)
else
warn("EchoMove: Echo does not have a PrimaryPart")
end
else
warn("EchoMove: Character does not have a PrimaryPart")
end
end
end
function EchoesAbilities:EchoFrenzy(player)
if activeEchoes[player] and #activeEchoes[player] > 0 then
for _, echo in ipairs(activeEchoes[player]) do
if echo and echo:FindFirstChild("Humanoid") then
local humanoid = echo.Humanoid
local originalWalkSpeed = humanoid.WalkSpeed
humanoid.WalkSpeed = originalWalkSpeed * 2
task.delay(ECHO_FRENZY_DURATION, function()
if echo and echo.Parent then
humanoid.WalkSpeed = originalWalkSpeed
end
end)
end
end
end
end
function EchoesAbilities:EchoDisrupt(player)
if activeEchoes[player] and #activeEchoes[player] > 0 then
for _, echo in ipairs(activeEchoes[player]) do
if echo and echo.PrimaryPart then
local echoPosition = echo:GetPrimaryPartCFrame().Position
for _, otherPlayer in ipairs(Players:GetPlayers()) do
if otherPlayer ~= player and otherPlayer.Character then
for _, enemyEcho in ipairs(activeEchoes[otherPlayer] or {}) do
if enemyEcho and enemyEcho.PrimaryPart then
local enemyEchoPosition = enemyEcho:GetPrimaryPartCFrame().Position
if (echoPosition - enemyEchoPosition).Magnitude <= ECHO_DISRUPT_RANGE then
local enemyHumanoid = enemyEcho:FindFirstChild("Humanoid")
if enemyHumanoid then
local originalWalkSpeed = enemyHumanoid.WalkSpeed
enemyHumanoid.WalkSpeed = originalWalkSpeed / 2
task.delay(ECHO_DISRUPT_DURATION, function()
if enemyEcho and enemyEcho.Parent then
enemyHumanoid.WalkSpeed = originalWalkSpeed
end
end)
end
end
end
end
end
end
end
end
end
end
return EchoesAbilities