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

Why am I getting 0 points when I start?

Asked by 9 years ago

I have a script that's supposed to give you 500 points when you join if you have a gamepass, and 1000 points when you join if you have another or both.

game.Players.PlayerAdded:connect(function(plr)
    local p = Instance.new('IntValue',plr)
    p.Name = 'Points'
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,252253525 --[[ 500 points ]]) then
        if not game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,252255271) then
            p.Value = 500
        end
    elseif game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,252255271 --[[ 1000 points ]]) then
        p.Value = 1000
    else
        p.Value = 0
    end
end)

The thing is I get 0 points when I join and I have both. There are no errors either.

I'm also new to gamepasses and MarketplaceService

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Code Fixes

You have the right idea but how you're doing this is probably messing it up. Try just checking if they have the 1000, if they don't then check if they have the 500, if not then give them 0



Efficiency Fixes

  • Make a variable for defining MarketplaceService

If you do this, you won't have to type out game:GetService('MarketplaceService') so many times

  • Make a table for your gamepasses

This is just for organization

  • Consider using standard roblox leaderboard setup

If you're expecting a leaderboard setup, you need to have a 'leaderstats' value in the player, and any stats as direct descendants if that value. This is completely up to you though.



Code

local ms = game:GetService('MarketplaceService')
local passes = {
    Thousand = 252255271,
    Hundred = 252253525
}

game.Players.PlayerAdded:connect(function(plr)
    local p = Instance.new('IntValue',plr)
    p.Name = 'Points'
    if ms:PlayerOwnsAsset(plr,passes.Thousand) then --1000
        p.Value = 1000
    elseif ms:PlayerOwnsAsset(plr,passes.Hundred) --500
        p.Value = 500
    else --0
        p.Value = 0
    end
end)
0
Didn't think of a leaderboard setup but I'll try... http://gyazo.com/ec4a6378999fdb5372474ff2d5cf98fa is what i want the game to look like. Senor_Chung 210 — 9y
0
If you want something like that then there's no need for a leaderboard setup(: That was just in case you were meaning for this to be on a roblox leaderboard, Goulstem 8144 — 9y
Ad

Answer this question