Check if player has died atleast once

  1. What do you want to achieve?
    Prevent respawn animation from playing the first time player join and only play if the player has died once

  2. What is the issue?
    Player still Play the respawn animation after they joined I have tried using a tag but I have no knowledge of how to keep player’s tag after they respawn

  3. What solutions have you tried so far?
    I tried using collectiveservice to give player a tag with .Died event but tag got reset after they respawn

Humanoid.Died:Connect(function()
	dash:Destroy()
	local Ouch = script.soundeffect:WaitForChild("ouch")
	Ouch:Play()
	Highlight:Destroy()
	local colorEffect = Instance.new("ColorCorrectionEffect", game.Lighting)
	colorEffect.TintColor = Color3.new(1,0,0)
	camShake:Shake(CameraShaker.Presets.Bump)
	wait(.1)
	colorEffect:Destroy()
	local CollectionService = game:GetService("CollectionService")
	local obj = script.Parent
	CollectionService:AddTag(obj,"Died")
end)

This is localscript for checking if player died

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		wait(1)
		local Humanoid = Character:FindFirstChild("Humanoid")
		local Highlight = Instance.new("Highlight", Character)
		Highlight.FillColor = Color3.fromRGB(255, 0, 0)
		Highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
		Highlight.FillTransparency = .5
		Highlight.Enabled = false
		if Character:HasTag("Died") then
			local animation = Instance.new("Animation")
			animation.AnimationId = "http://www.roblox.com/asset/?id=127917966861716"

			local animationTrack = Humanoid:LoadAnimation(animation)
			animationTrack:Play()
			animationTrack:GetMarkerReachedSignal("Glowing"):Connect(function(paramString)
				Highlight.Enabled = true
			end)
			animationTrack:GetMarkerReachedSignal("StopGlowing"):Connect(function(paramString)
				Highlight:Destroy()
			end)
		end
		task.wait()
	end)
end)

this is respawn script
I’m still new to lua coding so if you could please explain what the solution is and what the said funtion do, thank you

2 Likes

Tags are getting removed after player death.
You can make the folder with values such as bool value, when player joins to the game. When player dies you can check if that value is true or false. If it’s false you can set it to true and play the respawn animation. It should prevent playing the animation after dying more than once.

Also I suggest to make the folder (and value) and change the value in normal Script in ServerScriptService, just like you make leaderstats and change values in it.

2 Likes