Scripts wont work after character death

So, I dont exactly know how this COULD be happening since everything is replicated but meh.

The main details about the scripts are that they are essentially a module script and a client receiver communicating to make player movement mechanics Ex: Dashing/Sprinting

Maybe its because I am using a module script?

Module Script:

local Movement = {}

--//Services
local Players = game:GetService("Players")
local DebrisService = game:GetService("Debris")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local StarterPlayer = game:GetService("StarterPlayer")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

--//Global Variables
local Player = Players.LocalPlayer
local Character = Player.Character 
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")

local Camera = workspace.CurrentCamera

--//Resources
local ReplicatedAssets = ReplicatedStorage.Assets

local Animations = ReplicatedAssets.Animations
local Values = ReplicatedStorage.Communication.Values
local SFX = ReplicatedAssets.SFX
local VFX = ReplicatedAssets.Effects

--//Modules
local Modules = ReplicatedStorage.Modules

local CustomForce = require(Modules.Manager.Combat.CustomForce)
local GlobalModule = require(Modules.Manager.Effects.Global)
local GlobalCombatModule = require(Modules.Manager.Combat.Global)
local HitboxModule = require(Modules.Manager.Combat.HitboxManager)

--Tables
local DashSettings = {
	["MovingPart"] = RootPart;
	["Direction"] = "Front";
	["DirectionBoost"] = 0;
	["Blacklist"] = CustomForce.BlacklistPlayer(Character);
	["UpdateRate"] = 0.01;

	["RayWater"] = true;
	["FramePerSecond"] = 240;
	["DebugMode"] = false;

	["LockXRotation"] = true;
	["LockYRotation"] = false;
	["LockZRotation"] = true;
}


local SideDashSettings = {
	["MovingPart"] = RootPart;
	["Direction"] = "Left";
	["DirectionBoost"] = 0;
	["Blacklist"] = CustomForce.BlacklistPlayer(Character);
	["UpdateRate"] = 0.01;

	["RayWater"] = true;
	["FramePerSecond"] = 240;
	["DebugMode"] = false;

	["LockXRotation"] = true;
	["LockYRotation"] = false;
	["LockZRotation"] = true;
}

local KeyStates = {
	W = false,
	A = false,
	S = false,
	D = false
}

local DashForce = CustomForce.new(DashSettings)
DashForce:Activate(true)

local SideDashForce = CustomForce.new(SideDashSettings)
SideDashForce:Activate(true)


--//Booleans/Variables

--Movers
local DashMove = false
local DashDuration = 0.35
local DashSpeed = 0.5

local SideDashMove = false
local SideDashDuration = 0.2
local SideDashSpeed = 0.75

--Sprint
local SprintSpeed = 24
local NormalSpeed = 12
local SprintCooldown = .8
local SprintDebounce = false
local CanSprint = false


--//Sounds
local MovementSfx = SFX.Movement

local DashSound = MovementSfx.Dash

--//ClientFunctions

local function UpdateSprintState()
	
	if KeyStates.W and not KeyStates.S then
		CanSprint = true
	else
		CanSprint = false
	end
	
end

local function onInputBeganSprint(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.W then
		KeyStates.W = true
	elseif input.KeyCode == Enum.KeyCode.A then
		KeyStates.A = true
	elseif input.KeyCode == Enum.KeyCode.S then
		KeyStates.S = true
	elseif input.KeyCode == Enum.KeyCode.D then
		KeyStates.D = true
	end

	UpdateSprintState()
end

local function onInputEndedSprint(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.W then
		KeyStates.W = false
	elseif input.KeyCode == Enum.KeyCode.A then
		KeyStates.A = false
	elseif input.KeyCode == Enum.KeyCode.S then
		KeyStates.S = false
	elseif input.KeyCode == Enum.KeyCode.D then
		KeyStates.D = false
	end

	UpdateSprintState()
end


--//InputEvents
UserInputService.InputBegan:Connect(onInputBeganSprint)
UserInputService.InputEnded:Connect(onInputEndedSprint)


--//ModuleFunctions

function Movement.StartDash(direction: string, Animation, Sound): ()
	
	if Humanoid:GetState() == Enum.HumanoidStateType.Physics or Humanoid:GetState() == Enum.HumanoidStateType.Seated or Humanoid:GetState() == Enum.HumanoidStateType.Swimming or Humanoid:GetState() == Enum.HumanoidStateType.Climbing or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return
	end
	
	task.spawn(function()
		Character:SetAttribute("Dashing",true)
		task.wait(1.5)
		Character:SetAttribute("Dashing",false)
	end)
	
	--Global
	GlobalModule.SoundEffect(DashSound,RootPart)
	GlobalModule.ShakeCamera(3, 2, 0, .5,0.5)
	GlobalModule.Highlight(.1,.5,Character)
	GlobalModule.Blur(.1,.7,Character)
	
	GlobalModule.LimbTrail(Character["Right Arm"],.44)
	GlobalModule.LimbTrail(Character["Left Arm"],.44)
	

	
	Animation:Play()
	Sound:Play()
	
	DashForce:UpdateKey("Direction", direction)
	DashForce:UpdateKey("DirectionBoost", DashSpeed)
	DashMove = true

	task.delay(DashDuration, function()
		DashMove = false
		DashForce:UpdateKey("DirectionBoost", 0)
	end)
end

function Movement.StartSideDash(direction: string, Animation, Sound): ()

	if Humanoid:GetState() == Enum.HumanoidStateType.Physics or Humanoid:GetState() == Enum.HumanoidStateType.Seated or Humanoid:GetState() == Enum.HumanoidStateType.Swimming or Humanoid:GetState() == Enum.HumanoidStateType.Climbing or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return
	end

	task.spawn(function()
		Character:SetAttribute("Dashing",true)
		task.wait(1.5)
		Character:SetAttribute("Dashing",false)
	end)

	--Global
	GlobalModule.SoundEffect(DashSound,RootPart)
	GlobalModule.ShakeCamera(1, 1, 0, .3,.3)
	GlobalModule.Highlight(.1,.5,Character)
	GlobalModule.Blur(.1,.7,Character)

	GlobalModule.LimbTrail(Character["Right Arm"],.44)
	GlobalModule.LimbTrail(Character["Left Arm"],.44)

	Animation:Play()
	Sound:Play()

	SideDashForce:UpdateKey("Direction", direction)
	SideDashForce:UpdateKey("DirectionBoost", SideDashSpeed)
	SideDashMove = true
	
	task.delay(SideDashDuration, function()
		SideDashMove = false
		SideDashForce:UpdateKey("DirectionBoost", 0)
	end)
end



function Movement.Sprint(Animation)
	
	--StateCheck
	if Humanoid:GetState() == Enum.HumanoidStateType.Physics or Humanoid:GetState() == Enum.HumanoidStateType.Seated or Humanoid:GetState() == Enum.HumanoidStateType.Swimming or Humanoid:GetState() == Enum.HumanoidStateType.Climbing or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return
	end
	
	if Character:GetAttribute("Landed",true) then return end
	local MoveMagnitude = Humanoid.MoveDirection.Magnitude == 0

	--Debounces
	if SprintDebounce == true then return end
	if MoveMagnitude then return end
	if CanSprint == false then return end
	
	--Cooldown
	task.spawn(function()
		SprintDebounce = true
		task.wait(SprintCooldown)
		SprintDebounce = false
	end)

	--General
	if Animation then
		Animation:Play()
	end
	
	Humanoid.WalkSpeed = SprintSpeed
	Humanoid.JumpHeight = 5
	
	--Attributes
	Character:SetAttribute("Sprinting",true)
	
	--RunserviceChecks
	RunService.Heartbeat:Connect(function() 
		if Humanoid:GetState() == Enum.HumanoidStateType.Jumping then
			Animation:AdjustSpeed(0.2)
		elseif Humanoid:GetState() == Enum.HumanoidStateType.Landed then
			Animation:AdjustSpeed(1)
		end
		UpdateSprintState()
		
		if KeyStates.S == true then 
			Movement.StopSprint(Animation)
		end
	end)

	
end

function Movement.StopSprint(Animation)
	
	Character:SetAttribute("Sprinting",false)
	
	--General
	Animation:Stop()

	Humanoid.WalkSpeed = NormalSpeed
	Humanoid.JumpHeight = 4
	
end

function Movement.Land(Animation,Sound)
	
	task.spawn(function()
		Character:SetAttribute("Landed",true)
		task.wait(1.5)
		Character:SetAttribute("Landed",false)
	end)
	
	task.spawn(function()
		--Global
		GlobalCombatModule.StunToUnstun(Humanoid,RootPart,1,true)
		GlobalModule.Highlight(0,1,Character)
		GlobalModule.Blur(0,2,Character)
	end)

	--General
	Animation:Play()
	Sound:Play()
	GlobalModule.ShakeCamera(10, 5, 0, .5,0.5)
end

return Movement

Client Receiver

--!optimize 2
--!strict

--//Services
local Players = game:GetService("Players")
local DebrisService = game:GetService("Debris")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local StarterPlayer = game:GetService("StarterPlayer")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

--//Modules
local Modules = ReplicatedStorage.Modules

local CombatController = require(Modules.Controllers.Combat)
local MovementController = require(Modules.Controllers.Movement)

local GlobalManagerModule = require(Modules.Manager.Combat.Global)
local RockModule = require(Modules.Manager.Effects.RockModule)
local GlobalModule = require(Modules.Manager.Effects.Global)
--//Resources
local ReplicatedAssets = ReplicatedStorage.Assets
local Animations = ReplicatedAssets.Animations
local Values = ReplicatedStorage.Communication.Values
local SFX = ReplicatedAssets.SFX
local VFX = ReplicatedAssets.Effects

--//Global Variables
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = script.Parent:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")

local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()

--//RemotesFolders
local CommunicationFolder = ReplicatedStorage.Communication
local RemotesFolder = CommunicationFolder.Remotes
local CombatRemotesFolder = RemotesFolder.Combat

--//Remotes
local M1Remote = CombatRemotesFolder.M1
local SkillRemote = CombatRemotesFolder.Skill
local ParryRemote = CombatRemotesFolder.Blocking
local DashRemote = CombatRemotesFolder.Dash


--//States


--//Booleans/Variables
local DashCooldown = 4
local DashDebounce = false
local SideDashCooldown = 2
local SideDashDebounce = false

local SideDashSprintResetTime = 0.75
local DashSprintResetTime = 1.2
local M1SprintResetTime = 0.6

local Sprinting = false
local Parrying = false

local M1ResetTime = 0.25
local M1Reset = false
local FinalM1 = false
local FinalM1ResetTime = 2

local M1Count = 1

local MouseDown = false

--//Values
local AutoSprint = Values.AutoSprint

--//Keybinds


--//Animations

--Folders
local MovementAnimations = Animations.Movement
local DashAnimations = MovementAnimations.Dashes
local MiscMovementAnimations = MovementAnimations.Misc

local CombatAnimations = Animations.BasicCombat

local M1CombatAnimations = CombatAnimations["M1's"]
local HurtCombatAnimations = CombatAnimations.Hurt
local BlockAnimations = CombatAnimations.Block
local MiscCombatAnimations = CombatAnimations.Misc

--Movement
local LandAnimation = Character.Humanoid:LoadAnimation(MiscMovementAnimations.Land)
LandAnimation.Priority = Enum.AnimationPriority.Action4

local SprintAnimaton =  Character.Humanoid:LoadAnimation(MiscMovementAnimations.Sprint)
SprintAnimaton.Priority = Enum.AnimationPriority.Movement

local LeftDash = Character.Humanoid:LoadAnimation(DashAnimations.Left)
LeftDash.Priority = Enum.AnimationPriority.Action3

local RightDash = Character.Humanoid:LoadAnimation(DashAnimations.Right)
RightDash.Priority = Enum.AnimationPriority.Action3

local FrontDash = Character.Humanoid:LoadAnimation(DashAnimations.Front)
FrontDash.Priority = Enum.AnimationPriority.Action3

local BackDash = Character.Humanoid:LoadAnimation(DashAnimations.Back)
BackDash.Priority = Enum.AnimationPriority.Action3

--Combat

local DowmsmashCombatAnimation = M1CombatAnimations.Special.Downsmash
local UptiltCombatAnimation = M1CombatAnimations.Special.Uptilt

local BlockAnimation = BlockAnimations.Block
local BlockHitAnimation = BlockAnimations.BlockHit

local DashHitAnimation = MiscCombatAnimations.DashHit
local KnockBackAnimation = MiscCombatAnimations.KnockBack

local AnimationsCache = {}

--//Sounds
local MovementSfx = SFX.Movement

local DashSound = MovementSfx.Dash
local LandSound = MovementSfx.Land

--//Dependencies
Mouse.Button1Down:Connect(function()
	MouseDown = true
end)

Mouse.Button1Up:Connect(function()
	MouseDown = false
end)

--//MiscTables

--//ClientFunctions
local function SprintRestart(Time:number?)
	if Sprinting == false then return end
	task.spawn(function()
		MovementController.StopSprint(SprintAnimaton)
		task.wait(Time)
		MovementController.Sprint(SprintAnimaton)
	end)
end

local function MoveMagnitudeCheck()
	local MoveMagnitude = Humanoid.MoveDirection.Magnitude == 0

	if MoveMagnitude then
		MovementController.StopSprint(SprintAnimaton)
	end
end

--//UserInputService
UserInputService.InputBegan:Connect(function(input, isTyping, gameProcessedEvent)
	if gameProcessedEvent then return end
	if isTyping then return end
	
	--Sprint
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Sprinting = true
		MovementController.Sprint(SprintAnimaton)
	end

	--Variables
	local direction = nil
	local Animation = nil

	--Dash
	if input.KeyCode == Enum.KeyCode.Q then
		if UserInputService:IsKeyDown(Enum.KeyCode.W) then
			Animation = FrontDash
			direction = "Front"
		elseif UserInputService:IsKeyDown(Enum.KeyCode.S) then
			Animation = BackDash
			direction = "Back"
		end

		if direction then
			if DashDebounce == true then return end

			task.spawn(function()
				DashDebounce = true
				task.wait(DashCooldown)
				DashDebounce = false
			end)
			
			if direction == "Front" then
				CombatController.DashHitbox(0.35,RootPart)
			end
			
			SprintRestart(DashSprintResetTime)
			MovementController.StartDash(direction,Animation,DashSound)
		end
	end
	
	--SideDash
	if input.KeyCode == Enum.KeyCode.Q then
		if UserInputService:IsKeyDown(Enum.KeyCode.A) then
			Animation = LeftDash
			direction = "Left"
		elseif UserInputService:IsKeyDown(Enum.KeyCode.D) then
			Animation = RightDash
			direction = "Right"
		end

		if direction then
			if SideDashDebounce == true then return end

			task.spawn(function()
				SideDashDebounce = true
				task.wait(SideDashCooldown)
				SideDashDebounce = false
			end)
			
			SprintRestart(SideDashSprintResetTime)
			MovementController.StartSideDash(direction,Animation,DashSound)
		end
	end


end)

UserInputService.InputEnded:Connect(function(input, isTyping, gameProcessedEvent)
	if gameProcessedEvent then return end
	if isTyping then return end
	
	--Sprint
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Sprinting = false
		MovementController.StopSprint(SprintAnimaton)
	end
	
end)


--//StateChanged
Humanoid.StateChanged:Connect(function(OldState, NewState)
	if NewState == Enum.HumanoidStateType.Landed then
		if Character.Humanoid.RootPart.Velocity.Y < -125 and Character.Humanoid.FloorMaterial ~= Enum.Material.Air then
			
			MovementController.Land(LandAnimation,LandSound)
			
		end
		
	end
	
end)


--//RunService
RunService.Heartbeat:Connect(function()
	MoveMagnitudeCheck()
end)

Where’s the module parented? Correct me if I’m wrong, but from a quick glance it looks like you never update what the character variable is in the module.

Parented inside of a folder in replicated storage

Hmm do you ever update the character value in the module?

I’m not advanced at scripting yet but what do you mean by “Update”?

I thought called the local player then getting the character would work

Honestly i have no clue about how this happend and i have been trying to solve it for a day now

I dont think so no
keystrokkessssss

Well see after the player dies, the module doesnt change so the character value is still equal to their last character, when the player gets a new character you would need to change all values related to the character considering they are still using the character that died

OHHHHHHHHH
Is that because module scripts essentially act like tables or smth?

Anyways how do i do that? Update the character after death

Hmm well for starters this would be in the module btw:

local character = player.Character or player.CharacterAdded:Wait()

player.CharacterAdded:Connect(function(newChar)
     character = newChar
-- now in this code you would also need to reset the Humanoid variable, rootPart, and any other values that are connected to the character, for instance to change the humanoid you would just do
Humanoid = Character:WaitForChild("Humanoid") -- this would change it to the new humanoid
end

Yes exactly like that! if youll notice module is equal to a table, when the module calls the return function it returns the table (you could actually change what the return returned if you wanted to lol, wouldnt recommend it rn but if you ever wanted to for whatever reason.)

1 Like
Player.CharacterAdded:Connect(function(NewCharacter)
	Character = NewCharacter
	Humanoid = Character:WaitForChild("Humanoid") -- this would change it to the new humanoid
	RootPart = Character:WaitForChild("HumanoidRootPart")
end)

I did this but its not fixed yet, The client plays the animation but no walkspeed or dash is actually done

1 Like

Well if you look at the module youll notice you have like a lot of dictionaries that have values in them that are attached to the character, so youd have to change all of those.
If you really dont feel like doing that you could always parent the module to starterCharacterScripts so it would always be correct for ya and you wouldnt have to do all of this lol

Honestly yea, Ill just parent it to startercharacter.

THANKS A BUNCH! THIS WAS BUMMING ME OUT!

1 Like

All this works when you 1st set it up. So when they die, remove everything and clone in a fresh set.
This odd way of doing it should automatically clean up all lose ends. If that is even possible in this case.

Yup.
Literally works like perfect.
I am gonna go watch tutorials again i feel stupid

1 Like

Its ok, its always the simple things that confuse us the most

1 Like

Yea i just got told this :sweat_smile:
Thanks for the reply but the problem has been resolved!

1 Like

:rofl: Man
Im pretty sure im just dumb lol, didnt even think about what module scripts are

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.