Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
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)
0
I cant thank you enough! Im a small dev but im still learning. Thank you thank you thank you!! zeroimaginedragonsre 2 — 2y
0
np, it's not that hard :D santi_luly1 47 — 2y
Ad

Answer this question