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

Another gamepass script won't work, why is this the case?

Asked by 4 years ago

I have a tycoon game and a gamepass that spawns in a dropper when you buy it. But for some reason, it doesn't work. When you step on a button, the dropper spawns. Well when you already have the gamepass and you join in, it doesn't spawn the dropper in. I think it there's an error with scanning each tycoon to recognize which tycoon to give the dropper to, but I don't know how to fix it.

Here's my script:

local function getTycoonFromPlayer(player)
    for i,v in pairs(workspace.Tycoons:GetChildren()) do
        if v:IsA("Model") then
            if v.Owner.Value == player then
                return v
            end
        end
    end
    return nil
end
local marketplace = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)
    if marketplace:UserOwnsGamePassAsync(player.UserId, 6559657) then
        script.OwnsGamepass.Value = true
        local tycoon = getTycoonFromPlayer(player)
        if tycoon then
            local dropper = tycoon.Purchases:FindFirstChild("StarterDropper")
            if dropper then
                if tycoon.Owner.Value == nil then
                    repeat wait() until tycoon.Owner.Value == player return
                else
                    dropper.Parent = tycoon.PurchasedItems
                end
            end
        end
    end
end)

Any help is appreciated

0
Screen shot output when running the script Prestory 1395 — 4y

Answer this question