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

I think this if/then/else statement is breaking my money multiplying gamepass script, whats wrong?

Basically this script is supposed to detect whether you have a gamepass or not, and if you do it'll give you 2 Clicks (money) when you click the block, and if you don't you'll only get 1.

local passId = 4961932

function isAuthenticated(player) 
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

function Start(plr)
    print(plr.Name .. " has bought the game pass with id " .. passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) 

then local function OnClick(player)

    player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 2

    local f = Instance.new("Fire")
    f.Parent = script.Parent.Head
    game:GetService("Debris"):AddItem(f, .2)
	
	
else local function OnClick(player)

    player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1

    local f = Instance.new("Fire")
    f.Parent = script.Parent.Head
    game:GetService("Debris"):AddItem(f, .2)

end

script.Parent.ClickDetector.MouseClick:Connect(OnClick)

The else is underlined red, and I'm not sure why. Right now the block doesn't give any Clicks at all.

This script works just fine, but it doesn't include the gamepass detector, and will only give 1 click regardless of if you have a gamepass or not.

local function OnClick(player)

    player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + 1

    local f = Instance.new("Fire")
    f.Parent = script.Parent.Head
    game:GetService("Debris"):AddItem(f, .2)

end

script.Parent.ClickDetector.MouseClick:Connect(OnClick)

Could someone tell me what the issue is?

1 answer

###First let me get this off my chest:

#Your Indentation

###Your indentation is extremely inconsistent. Some lines are correctly indented whilst some aren't. You have your then in one line and the if in another line, and have else local function all in one line. Scripts can sometimes underline when the lines are poorly indented.

#The Problem

###The GamePassService:PlayerHasPass() method has been broken due to the new game pass update. Use MarketplaceService:UserOwnsGamePassAsync().

local MarketplaceService = game:GetService('MarketplaceService') -- use this 
local passId = 4961932
local amt = 1 -- amount of clicks to give 

local function isAuthenticated(userId)  -- the player's UserId is the argument, not the player itself
    return MarketplaceService:UserOwnsGamePassAsync(userId, passId)
end

local function Start(plr)
    print(plr, "has bought the game pass with id", passId)
end


script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if isAuthenticated(plr.UserId) then
        player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + amt*2
        -- multiply 1 by 2, giving us 2 ofc
    else -- doesn't own game pass
        player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + amt -- no multiplying 
    end
end)

--[[ 
    The PlayerAdded event was useless. 
    Simply check when they click the button, makes life easier.
]]--

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