How do I fix my revive script

I’m trying to make a script that allows players to pay if they want to revive, however I’m having some problems.
When the player dies and pays to revive, they arent revived and just stay died. How would i be able to make them respawn

local player = plr.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local function unlockMouse()
	local mouseUnlocker = Instance.new("TextButton")
	mouseUnlocker.Parent = script.Parent
	mouseUnlocker.Modal = true
	mouseUnlocker.Size = UDim2.new(0,0,0,0)
	mouseUnlocker.Name = "mouseunlocker"
	mouseUnlocker.Text = ""
end
local function lockMouse()
	if script.Parent:FindFirstChild("Unlocker") then
		script.Parent.Unlocker:Destroy()
	end
end
humanoid.Died:connect(function()
	print("died")
	script.Parent.Parent.Enabled = true
	unlockMouse()
end)

--- text button script


server script service script

local DataStoreService = game:GetService("DataStoreService")

local id = 11955511685

game.Players.CharacterAutoLoads = false

game.Players.PlayerAdded:Connect(function(plr)
	print("player added")
	plr:LoadCharacter()
	local aliveplayers = Instance.new("ObjectValue",workspace.AlivePlayers)
	aliveplayers.Name = plr.Name
	aliveplayers.Value = plr
	local hum = plr.Character:WaitForChild("Humanoid")
	hum.Died:connect(function()
		print("died")
		local vale = workspace.AlivePlayers:FindFirstChild(plr.Name)
		vale:Destroy()
	end)
end)

function processReceipt(receiptInfo)
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if receiptInfo.ProductId == id then
		print("player revived")
		player:LoadCharacter()
		local aliveplayers2 = Instance.new("ObjectValue",workspace.AlivePlayers)
		aliveplayers2.Name = player.Name
		aliveplayers2.Value = player
		local hum = player.Character:WaitForChild("Humanoid")
		hum.Died:connect(function()
			print("died")
			local aliveplayerss = workspace.AlivePlayers:FindFirstChild(player.Name)
			aliveplayerss:Destroy()
		end)
		return Enum.ProductPurchaseDecision.PurchaseGranted		
	end
end


MarketplaceService.ProcessReceipt = processReceipt
1 Like

When a humanoid dies, it dies. You cannot “un-die” it. However, there are two ways I can come up with at the top of my head to implement this:

1. Fake death
To do this you’ll have to do this wherever damage is dealt. You will have to intercept any damage which would kill the humanoid and instead set the HP to 1 and alert whatever needs know know it has “died”.

2. Swap-a-roo
As stated before, you cannot un-die (or revive as some may call it) a humanoid once it has died. This doesn’t mean you cannot replace it. When a player dies, swap the dead character with a new one either when they are in the (presumably) “downed” state or when they are to be revived, whichever makes more sense in your situation.

So would i just reload the character, and respawn them for the 2nd option?

Just do Player:LoadCharacter() if they revived. If you want to move them to their death point, just make a Part when they die and if they decide to revive, then you call Player:LoadCharacter() and then move them to that part.

Or just make a fake NumberValue in the character that’s called Health and when that reaches 0, you go into a downed state. Play an animation then and if they revive, change the Value of the “Health” to 100 and stop playing the animation.

This may make you have to rewrite most of your code.

That is correct. You’d probably want to teleport them to the position they were at when they died though, or however your revive thing would work.

Did this, thanks! (30charrrrrrrs)

Did it work? Don’t forget to mark correct response as the solution to close this once it is resolved!

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