-
What do you want to achieve?
I want to change my opponent’s HP, but I can’t do it because before he manages to get the opponent’s name, he won’t even have time to respawn and I’m thinking about how to do it.
Script:
function spawnEnemy(enemyModel, spawnPoint, clonedEnemy)
local clonedEnemy = enemyModel:Clone()
clonedEnemy.HumanoidRootPart.CFrame = spawnPoint.CFrame + Vector3.new(0,3,0)
clonedEnemy.Parent = workspace
return clonedEnemy
end
for _, spawnPoint in ipairs(spawnerlist) do
local respawnTime = spawnPoint:GetAttribute("RespawnTime")
local enemyName = spawnPoint:GetAttribute("EnemyName")
local enemyModel = game.ServerStorage.Enemies[enemyName]
local function spawnNewEnemy()
local spawnedEnemy = spawnEnemy(enemyModel, spawnPoint)
local humanoidConnection
local enemyHealth = CombatSettings.Settings.Mobs[enemyName].Statistic.Health -- This Line
humanoidConnection = spawnedEnemy:WaitForChild("EnemyHumanoid").Died:Connect(function()
humanoidConnection:Disconnect()
task.delay(respawnTime, function()
despawnEnemy(spawnedEnemy)
spawnNewEnemy()
end)
end)
end
spawnNewEnemy()
end
ModuleScript:
local CombatSettingsPlayer = {
["Mobs"] = {
["Knight"] = {
["Statistic"] = {
["MaxHealth"] = 80,
["Health"] = 80,
["Speed"] = 20,
}
}
}
}
return CombatSettingsPlayer
-
What is the issue?
The code tries to get the name of the opponent before it appears. -
What solutions have you tried so far?
I looked in the roblox documentation and devforum, but I can’t find anything