if receiptInfo.ProductId == productIds["LoopKill"] then
if player then
local msgService = game:GetService("MessagingService")
msgService:SubscribeAsync("PlayerBoughtLoopKill!", function()--I am making it so that the product works for all the servers.
local screenGui = game:GetService("ReplicatedStorage"):WaitForChild("LoopKillFolder").LoopKill
local waitUntilDone = game:GetService("ReplicatedStorage"):WaitForChild("LoopKillFolder").LoopKillWait:Clone()--Addes gui that says your loop kill timer will start after the other one ends.
local players = game.Players:GetChildren()
for i, v in pairs(players) do
local screenGuiClone
local messageLabel
local newPurchase = false--If someone buys something while the for loop is still going
if v:WaitForChild("PlayerGui"):FindFirstChild("LoopKillClone") == nil then
screenGuiClone = screenGui:Clone()
screenGuiClone.Name = "LoopKillClone"
screenGuiClone.Parent = v:WaitForChild("PlayerGui")
elseif v:WaitForChild("PlayerGui"):FindFirstChild("LoopKillClone") then
waitUntilDone.MessageLabel.Visible = true
waitUntilDone.Parent = player:WaitForChild("PlayerGui")
newPurchase = true
end
messageLabel = screenGuiClone.MessageLabel
for i = 10, 0, -1 do
if player.Name ~= player.DisplayName then
messageLabel.Text = player.Name.. "(@" .. player.DisplayName .. ") just bought LoopKill! You will be loopkilled for " .. i .. " seconds!"
elseif player.Name == player.DisplayName then
messageLabel.Text = player.Name.. "(@" .. player.DisplayName .. ") just bought LoopKill! You will be loopkilled for " .. i .. " seconds!"
end
if i == 0 then--This is the part it is malfunctioning. Every time the loop starts, it always just makes this part happen right away. How do I fix this?
if newPurchase == true then
print("True")
i = 180
else
local clones = v:WaitForChild("PlayerGui"):WaitForChild("LoopKillClone")
print("Destroy")
clones:Destroy()
end
end
end
wait(1)
repeat wait() until i ~= -1
end
end)
What’s not working properly?
Scroll all the way to the bottom and the line is at the top
If you’re trying to kill all, you can use this.
task.spawn(function()
while true do
task.wait(180)
pcall(function()
for _,v in game:GetService("Players"):GetPlayers() do
v.Character.Head:Destroy()
end
end)
end
end)