Kill all DevProduct isn't working

I have a button in my game where if a user clicks it then it will prompt a purchase which works but what doesn’t work is it is supposed to kill everyone accepts for the person that is purchasing it.

This is the ServerScript that is placed in ServerScriptService:

local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")


local DevProductId = 1255384268


local function killAll(reciept)
	if (reciept.ProductId == DevProductId) then
		for i,v in pairs(game.Players:GetPlayers()) do
			if(v.UserId ~= reciept.PlayerId and v.Character and v.Character:FindFirstChild("Humanoid")) then
				v.Character:FindFirstChild("Humanoid").Health = 0
			end
		end
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	end
end

mps.ProcessReceipt = killAll
1 Like

I have this problem too, but mine is when purshacing points and coins.

Don’t you need to type killAll() ?

Just tried that and it didn’t make any difference.

Did it give you some kind of error?

Nope, no errors before or after changing it to killAll() instead

Maybe try mps.ProcessReceipt:Connect(killAll)

Nope, still not working and no errors.

what is ‘’(reciept)’’. Maybe i have it wrong but i don’t think you gave your first parameter something

idk I’m not a scripter, I had to watch a tutorial for the script which in the video I watched the video and it worked for him but not me.

I would suggest to take a look into this, instead of blindly following a youtube tutorial.

2 Likes

You can’t use

LocalPlayer

in a server script

Try that. I’ve instead, made it search through workspace for any objects with humanoids, which would be the player’s character.

Sorry for late response just got back on my PC and checked the devforum… I tried this and still nothing changed and no errors

The script seems fine but you didn’t say what isn’t working. Did you try debugging it with prints to see where it stops?

Do I just type print(“print”) at the top of the script?

local function killAll(reciept)
    print("invoked callback") 
	if (reciept.ProductId == DevProductId) then
        print("player bought the right product") 
		for i,v in pairs(game.Players:GetPlayers()) do
			if(v.UserId ~= reciept.PlayerId and v.Character and v.Character:FindFirstChild("Humanoid")) then
				v.Character:FindFirstChild("Humanoid").Health = 0
			end
		end
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	end
end

mps.ProcessReceipt = killAll

Continue adding prints after almost every statement/function, that’s a way to debug and see where the script stops also do you get any errors in the console?

I added the new script that you listed and I am getting no print messages or error messages in the console or studio output

Oh dear god please don’t do this.

You can use breakpoints and stepping to do this the right way.

See Debugging Tools.

1 Like

ProcessReceipt is a callback function, not an event; you’re supposed to specify a function to call when ProcessReceipt is triggered, not call it yourself.
https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

2 Likes