Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to do that when I kill an npc/zombie, it gives me double money with a gamepass???

Basically I want that when I kill a monster, and you have my double money gamepass, it gives you the double money when you kill a monster. I have tried many different alternatives but it comes to no solution, pls help me

This is the code I have tried that is inside the zombie model and is a script not local script

local Humanoid = script.Parent.Humanoid
local  MarketplaceService = game:GetService("MarketplaceService")
local  Players = game:GetService("Players")



local id = --gamepass id not sharing

function died()

local ms = game:GetService("MarketplaceService")
local haspass = ms:UserOwnsGamePassAsync(Player.Userid, id)
	
		local tag = Humanoid:FindFirstChild("creator")
		if tag ~= nil then
			if tag.Value ~= nil then
				local Leaderstats = tag.Value:FindFirstChild("leaderstats")
				if Leaderstats ~= nil then
					Leaderstats.Cash.Value = Leaderstats.Cash.Value +50
					wait(0.1)
					script.remove()

				end
			end
		end
	end
		
		
	end
end)

Humanoid.Died:Connect(died)

1 answer

✓ Accepted answer
local Humanoid = script.Parent.Humanoid
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ToGive = 50

local id = --gamepass id not sharing

local function died()
    local haspass = MarketplaceService:UserOwnsGamePassAsync(Player.Userid, id)
    local tag = Humanoid:FindFirstChild("creator")

    if tag ~= nil then
        if tag.Value ~= nil then
            local Leaderstats = tag.Value:FindFirstChild("leaderstats")
            if Leaderstats ~= nil then
                if haspass then
                    Leaderstats.Cash.Value += (ToGive * 2)
                else
                    Leaderstats.Cash.Value += ToGive
                end

                wait(.1)
                script.remove()
            end
        end
    end
end)

Humanoid.Died:Connect(died)

2 comments

0

I cant thank you enough! Im a small dev but im still learning. Thank you thank you thank you!!

0

np, it's not that hard :D

This discussion is preserved as it was. New answers, comments, and votes are closed.