How to disable combat scripts when you die

Hello, I have found out when playtesting my game and the combat in it that when you die you can still attack the opposition. How am I meant to disable the script when the player dies?

Use a function such as this:


local isAlive = (function (Player, ret) --> Requires [Player] instance, 'ret' is optional (determines whether you're returned a bool, or the character itself)
	local Character = Player.Character
	if not Character or not Character:IsDescendantOf(game.Workspace) or not Character:FindFirstChild "Humanoid" or Character.Humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return false
	end
	return ret and Character or (true)
end)

Add this check on every statement in which requires player input to perform the action, this can be added on the server too. Similarly, you could also disconnect the events locally - however, I would recommend you ensure you check this on the server when using remotes to give damage (alongside other sanity checks).

3 Likes

Thank you for your recommendation.