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

Gamepass counting extra money when player dosen't own gamepass?

Asked by 3 years ago

So my issue is I made a game pass that gives more cash per lap om a racing game the normal. But even players without the VIP (I tested on an alt) still get the extra 300 per lap. VIP is supposed to start as false but become true when the game detects a game pass is owned but it counts It as true for some stupid reason.

GamePassCheck script

vip = false
game.Players.PlayerAdded:connect(function(plyr)
    local gamePassService = game:GetService("GamePassService")
    if gamePassService:PlayerHasPass(plyr,12146561) then
        vip = true
    end
end)


LapCounter Script

function onTouch(part)
local searcher = part.Parent:findFirstChild("Humanoid")
if searcher ~= nil then
local finder = game.Players:findFirstChild(part.Parent.Name)
if finder == nil then return end
if finder.Cheeze.Value == 3 then
finder.leaderstats.Laps.Value = finder.leaderstats.Laps.Value + 1
finder.leaderstats.Cash.Value = finder.leaderstats.Cash.Value + 500
finder.Cheeze.Value = 0
if vip == true then
finder.leaderstats.Cash.Value = finder.leaderstats.Cash.Value + 300
end
end
end 
end

script.Parent.Touched:connect(onTouch)

Can someone explain what I did wrong?

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

as soon as one player has the game pass it will set vip to true meaning as soon as one player has the gamepass inthe lobby all the other players are "vip" too bc you dont keep a "vip" per player but one for every player

so what you have to do is keep a "vip" for each player, so we create a table that keeps a record for each player if they are vip

local vip = {}
local gamePassService = game:GetService("GamePassService") -- always save it in the highest scope possible
local MarketplaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:connect(function(plyr)
  -- if gamePassService:PlayerHasPass(plyr,12146561) then 
   --   table.insert(vip, plyr.UserId) 
  -- end
-- above function is deprecated as pointed out in the comments but i cant full replace it atm due to it using  assetid while the newer one use gamepass id so either you get the gamepass id and fill it in or you use the above
    if MarketplaceService:UserOwnsGamePassAsync(plyr.UserId, gamepassid) then  --fill in the gamepassid
        table.insert(vip, plyr.UserId) -- adds the userid of the player which has the gamepass
    end
end)


btw globals are bad always use local, connect is deprecated use Connect and indent your code

function onTouch(part)
    local searcher = part.Parent:FindFirstChild("Humanoid")
    if searcher ~= nil then
        local finder = game.Players:FindFirstChild(part.Parent.Name)
        if finder ~= nil and finder.Cheeze.Value == 3 then
            finder.leaderstats.Laps.Value += 1
            finder.leaderstats.Cash.Value += 500
            finder.Cheeze.Value = 0
            if table.find(vip, finder.UserId) then -- checks if it is in the table
                finder.leaderstats.Cash.Value += 300
            end
        end
    end 
end

script.Parent.Touched:Connect(onTouch)

btw you can also do var += 1 instead var = var +1, use more variables, findFirstChild is also deprecated

0
Another note, PlayerHasPass is also deprecated use :UserOwnsGamePassAsync() instead birds3345 177 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local plr = game.Players.LocalPlayer
local ID = 0 -- GamepassId
local MPS = game:GetService("MarketPlaceService")
local amnt = 25
script.Parent.Touched:Connect(function(hit)
local hit = hit.Parent -- If you want this this can be used as a kill brick but lets head on --
local RetrieveData = plr.leaderstats
local Cash = RetrieveData.Cash
Cash.Value = Cash.Value + amnt
haspass = MPS:UserOwnsGamePassAsync(plr.UserId, ID)
if haspass then
amnt = amnt * 2 -- if not do amnt *2 --
Cash.Value = Cash.Value + amnt
0
if your using a local script inside guis do this or atleast put scripts like this in replicatedstorage and name parts curten names, so lets say if hit.Parent.Name == "CashDrop" then do this stuff TradingForDom 1 — 3y
Log in to vote
0
Answered by 3 years ago

Ever since April 2018, you could no longer use PlayerHasPass(). You must now use UserOwnsGamePassAsync. Also, you don't use the player, you use it like this:

local MPS = gamel:GetService("MarketplaceService");

if MPS:UserOwnsGamePassAsync(player.UserId, id) then
    -- // code
end

Also PLEASE, PLEASE INDENT YOUR CODE! AND DON'T USE DEPRECATED FEATURES!

I'd also like you to check out VerdommeMans answer.

Answer this question