This is the serverscript:
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local id = 1842063465
local abletorevive = game.ReplicatedStorage.BoolValues.AbleToRevive
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:Connect(function(plr)
print("player added")
plr:LoadCharacter()
local val = Instance.new("ObjectValue",workspace.AlivePlayers)
val.Name = plr.Name
val.Value = plr
local hum = plr.Character:WaitForChild("Humanoid")
hum.Died:connect(function()
print("died")
local vale = workspace.AlivePlayers:FindFirstChild(plr.Name)
vale:Destroy()
if abletorevive.Value == false then
game.ReplicatedStorage.CannotRevive:FireClient(plr)
else
end
end)
end)
function processReceipt(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- script below controls what happens if bought
if receiptInfo.ProductId == id then
print("player revived")
player:LoadCharacter()
local val = Instance.new("ObjectValue",workspace.AlivePlayers)
val.Name = player.Name
val.Value = player
local hum = player.Character:WaitForChild("Humanoid")
hum.Died:connect(function()
print("died")
local vale = workspace.AlivePlayers:FindFirstChild(player.Name)
vale:Destroy()
end)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
MarketplaceService.ProcessReceipt = processReceipt
the script for the button:
local mps = game:GetService("MarketplaceService")
local id = 1842063465
local abletorevive = game.ReplicatedStorage.BoolValues.AbleToRevive
game.ReplicatedStorage.CannotRevive.OnClientEvent:Connect(function()
script.Parent.Text = "Wait"
end)
if abletorevive.Value == true then
script.Parent.Text = "Revive"
script.Parent.MouseButton1Click:Connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer,id)
end)
end
and the localscript:
print("loaded")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local num = 1
local gui = script.Parent
local spectateFrame = gui.SpectateFrame
local mainButton = gui.spectate
local plrName = spectateFrame.PlayerName
local nex = spectateFrame.Next
local prev = spectateFrame.Previous
local TeleportService = game:GetService("TeleportService")
local destinationPlaceId = 17670536058 -- Replace with the ID of the destination place
local success, err = pcall(function()
TeleportService:TeleportAsync(destinationPlaceId)
end)
local function SetCam(n)
local p = workspace.AlivePlayers:GetChildren()[n]
plrName.Text = p.Name
workspace.CurrentCamera.CameraSubject = p.Value.Character.Humanoid
end
local function unlockMouse()
local thing = Instance.new("TextButton")
thing.Parent = script.Parent
thing.Modal = true
thing.Size = UDim2.new(0,0,0,0)
thing.Name = "Unlocker"
thing.Text = ""
end
local function lockMouse()
if script.Parent:FindFirstChild("Unlocker") then
script.Parent.Unlocker:Destroy()
end
end
local function timer()
script.Parent.Timer.Visible = true
for i = 20,0,-1 do
script.Parent.Timer.Text = i
if #workspace.AlivePlayers:GetChildren() > 0 then
script.Parent.Timer.Text = 20
script.Parent.Timer.Visible = false
break
end
wait(1)
if i < 1 then
TeleportService:TeleportAsync(destinationPlaceId)
if not success then
print("Error teleporting: ", err)
end
end
end
end
hum.Died:connect(function()
print("died")
script.Parent.Enabled = true
unlockMouse()
end)
script.Parent.spectate.MouseButton1Click:Connect(function()
if #game.workspace.AlivePlayers:GetChildren() > 0 then
gui.revive.Visible = false
gui.spectate.Visible = false
gui.TextLabel.Visible = false
gui.returrn.Visible = true
spectateFrame.Visible = true
num = 1
SetCam(num)
end
end)
prev.MouseButton1Click:Connect(function()
if num > 1 then
num = num - 1
else
num = #workspace.AlivePlayers:GetChildren()
end
SetCam(num)
end)
nex.MouseButton1Click:Connect(function()
if num < #workspace.AlivePlayers:GetChildren() then
num = num + 1
else
num = 1
end
SetCam(num)
end)
script.Parent.returrn.MouseButton1Click:Connect(function()
gui.returrn.Visible = false
spectateFrame.Visible = false
gui.revive.Visible = true
gui.spectate.Visible = true
gui.TextLabel.Visible = true
workspace.CurrentCamera.CameraSubject = plr.Character.Humanoid
end)
workspace.AlivePlayers.ChildRemoved:Connect(function()
if #workspace.AlivePlayers:GetChildren() < 1 then
timer()
end
end)
I’ve tried something which was adding a bool value in ReplicatedStorage to check if its safe to revive or not. When it is not checked, the button says “Wait” but it still allows you to buy it.