Hello, the problem is when i do LoadCharacter the CharacterAdded just don’t detect i respawn ? ( my game have CharacterAutoLoad on False to avoid respawns auto ) and when i turn it on and delete the part that make me Respawn(the function) it works perfectly) so it’s just a problem with LoadCharacter and CharacterAdded events.
Here is the script :
local MarketPlaceService = game:GetService("MarketplaceService")
local DevProductId = 1630335722
local function getmaxlifes()
local startlifes = 3
return startlifes
end
local function DiedCam(plr)
local clo = script.DeathCam:Clone()
clo.Parent = plr.PlayerGui
clo.Enabled = true
end
local function repsawn(plr)
print("respawn")
local a = plr.PlayerGui:FindFirstChild("DeathCam")
if a then
a:Destroy()
end
plr:LoadCharacter()
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
repsawn(plr)
plr:SetAttribute("Lifes", getmaxlifes())
plr.CharacterAdded:Connect(function(char)
print(char)
char.Humanoid.Died:Connect(function()
print("died")
DiedCam(plr)
if plr:GetAttribute("Lifes") > 0 then
print("have lifes")
repsawn(plr)
local lifes = plr:GetAttribute("Lifes") - 1
plr:SetAttribute("Lifes", lifes)
elseif plr:GetAttribute("Lifes") == 0 then
MarketPlaceService:PromptProductPurchase(plr, DevProductId)
print("prompts")
else
print("error")
end
end)
end)
end)
game:GetService("ReplicatedStorage").PromptRespawn.OnServerEvent:Connect(function(plr)
MarketPlaceService:PromptProductPurchase(plr, DevProductId)
end)
MarketPlaceService.PromptProductPurchaseFinished:Connect(function(UserId, ProductId, IsPurchased)
local player
for _,v in pairs(game:GetService("Players"):GetChildren()) do
if v.UserId == UserId then
player = v
end
end
if ProductId == DevProductId and IsPurchased == true then
repsawn(player)
end
end)
Sincerely,
@hollaquetalBRUH