local ActorSystem = {
Connections = {},
KillerIntros = {}
}
local Player = game.Players.LocalPlayer
local Network = require(game.ReplicatedStorage.Modules.Network)
local Actors = require(game.ReplicatedStorage.Modules.Actors)
local Util = require(game.ReplicatedStorage.Modules.Util)
local Sprint = require(game.ReplicatedStorage.Systems.Character.Game.Sprinting)
function ActorSystem.Start()
Network:SetConnection("ActorDestroyed", "REMOTE_EVENT", function(actor)
local current = Actors.CurrentActors[actor]
if current then
for _, phase in pairs({"Destroyed", "DestroyedPost"}) do
if current.CustomBehavior and current.CustomBehavior[phase] then
current.CustomBehavior[phase](current.CustomBehavior, current)
elseif current.Behavior[phase] then
current.Behavior[phase](current.Behavior, current)
end
end
task.spawn(function()
if current.ActorType:find("Killer") then
local ChaseThemes =
require(game.ReplicatedStorage.Systems.Character.Game.ChaseThemes)
require(game.ReplicatedStorage.Systems.Character.Game.ChaseThemesKiller)
ChaseThemes:KillerRemoved(current)
end
end)
Actors.__actorDestroyed:Fire(current)
end
Actors.CurrentActors[actor] = nil
end)
Network:SetConnection("ActorCreated", "REMOTE_EVENT", function(actorInfo)
local skinData = Actors:ApplySkinDataToActorInfo(actorInfo)
actorInfo.CustomBehavior = skinData and
(skinData:FindFirstChild("Behavior") and require(skinData.Behavior)) or {}
Actors.CurrentActors[actorInfo.Player] = actorInfo
Util:PreloadAssets(actorInfo.Config)
if actorInfo.Player == Player then
ActorSystem:Destroy()
-- animations setup omitted for brevity --
-- Stamina integration
task.spawn(function()
if Sprint.Character ~= actorInfo.Rig or not Sprint.DefaultsSet then
local waited = 0
repeat
waited += game.RunService.Heartbeat:Wait()
until Sprint.Character == actorInfo.Rig and Sprint.DefaultsSet
or waited >= 10
end
Sprint.SprintSpeed = actorInfo.Config.SprintSpeed or
Sprint.SprintSpeed
Sprint.StaminaLoss = actorInfo.Config.StaminaLoss or
Sprint.StaminaLoss
Sprint.StaminaGain = actorInfo.Config.StaminaGain or
Sprint.StaminaGain
Sprint.MaxStamina = actorInfo.Config.MaxStamina or
Sprint.MaxStamina
Sprint.MinStamina = actorInfo.Config.MinStamina or
Sprint.MinStamina
-- Preserve stamina value instead of resetting it
Sprint.Stamina = math.clamp(Sprint.Stamina or Sprint.MaxStamina,
Sprint.MinStamina, Sprint.MaxStamina)
Sprint.__staminaChangedEvent:Fire(Sprint.Stamina)
-- Proper bounds check
if Sprint.Stamina < Sprint.MinStamina or Sprint.Stamina >
Sprint.MaxStamina then
Player:Kick("\n\nPranksterComet 000:\nInvalid stamina value")
end
-- Killers always drain stamina unless explicitly disabled
externally
if actorInfo.ActorType:find("Killer") and actorInfo.Rig and
actorInfo.Rig.PrimaryPart then
ActorSystem.Connections.StaminaDrainConnection =
game.RunService.RenderStepped:Connect(function()
Sprint.StaminaLossDisabled = false
end)
end
end)
end
Actors.__actorCreated:Fire(actorInfo)
end)
end
function ActorSystem.Destroy()
if ActorSystem.AbilityHotbar then
ActorSystem.AbilityHotbar:Destroy()
end
for _, conn in pairs(ActorSystem.Connections) do
conn:Disconnect()
end
table.clear(ActorSystem.Connections)
end
return ActorSystem