Combat not working after death

so i have completed my combat system, and i’am very pleased with it; however when i die it does not work… here is how i formatted my stuff

Screen Shot 2020-06-20 at 10.40.50 PM
ignore magic modulescript

the code in Core is the following:

for _, Module in pairs(script:GetChildren()) do
	if Module:IsA("ModuleScript") then
		require(Module)
	end
end

and Controls script contents being:

for _, Module in pairs(script:GetChildren()) do
	if Module:IsA("ModuleScript") then
		require(Module)
	end
end

return nil

not sure if this matters but inside Combat the script uses this to define the player

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

these scripts are located in starterplayer>starterplayerscripts; please do not tell me to move them unless you would know how to fix the script (when i move the module structure into any other area it will break)

if you need the full code please tell me (:

after i die here is the error in the output:

(this is coming from the animation module so here is the code for animation module)

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Assets
local Assets = ReplicatedStorage:WaitForChild("Assets")
local Animations = Assets:WaitForChild("Animations")

local Binds = ReplicatedStorage:WaitForChild("Binds")
local GetTrack = Binds:WaitForChild("GetTrack")
local Animate = Binds:WaitForChild("Animate")

--// Module
local Animator = {
Play = function(Humanoid,AnimationName)
	local Animation = Animations:FindFirstChild(AnimationName)
	if Animation then
		local Track = Humanoid:LoadAnimation(Animation)
		Track:Play()
	end
end,
PrepeareTrack = function(Humanoid,AnimationName)
	local Animation = Animations:FindFirstChild(AnimationName)
	if Animation then
		local Track = Humanoid:LoadAnimation(Animation)
		return Track -- returns a already set up animation track so it can be used later
	end
end,
}

--//Main
GetTrack.OnInvoke = function(Humanoid,AnimationName)
	return Animator.PrepeareTrack(Humanoid, AnimationName)
end

Animate.Event:Connect(function(Humanoid,AnimationName,Task)
	Animator[Task](Humanoid,AnimationName)
end)

return Animator

(how it fires to the animator)

		local Track = GetPlayerTrack(Character:WaitForChild("Humanoid"),Combos[ComboCount])
		Track:AdjustSpeed(1.5)
		Track:Play()

TDLR; why is my combat breaking after i die?!

Does the main script exist inside of StarterCharacterScripts or StarterPlayerScripts. I presume this is trying to load an animation before the player’s humanoid has actually reinserted into workspace.

I suggest moving it into StarterCharacterScripts if you haven’t already done so and try using a :WaitForChild to wait for the Humanoid to be reinserted.

If these two steps didn’t help please let me know as I’ve got a few other ideas. Thanks! :slightly_smiling_face:

1 Like

the main script exists in starterplayerscripts, when i move it into startercharacterscripts it breaks (like when i move the core script with everything else in it or whatever)

Why does it break when you move it to StarterCharacterScripts? Remember that the script now exists INSIDE of your player model (workspace.ConnectionSuccess). This makes it reset every time you respawn. Try reading over your variables and ensure they now reference things correctly. I am pretty sure this will sort your issue as the script will ONLY run once the Humanoid has loaded in meaning animations can’t be loaded onto a non-existant humanoid which causes errors.

Let me know if you still need help!

as you can see https://gyazo.com/33df1e3f474f7340c0aac98f3caa7ede it does nothing, usually it will load animations and work tho…

(core consists of everything)

I’ve had the same problem as you, the solution is to put a wait() at the beginning, however I strongly advise against doing that, here’s why: Avoiding wait() and why

Then you have to reference the new character every time the player’s character dies. Doing this is not enough:

Use this as a reference:

Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
end)

so would my character variable be

local Character = Player.CharacterAdded:Connect(function(NewCharacter)
    Character = NewCharacter
end)

edit: broke again, not sure if i am doing this right

local Character1 = Player.Character or Player.CharacterAdded:Wait()
local Character = Player.CharacterAdded:Connect(function(NewCharacter)
    Character1 = NewCharacter
end)

edit2: i moved the script into starterplayerscripts to test if that method worked there and when i did it said in a place where i was referencing the character “WaitForChild is not a valid member of RBXScriptConnection” so possibly is that referencing the character wrong?

didn’t work either, but thanks for that post, useful

1 Like