Time script help

I am new to scripting.

Trying to make a script that adds +1 for every 12 seconds if you have a gamepass and +1 for ever 60 seconds if you dont.

local gmpsID = 15484617
	
if "Make it check if player has pass" then
	while true do
		wait(12)
		--- Add 1 time in leaderstats
	end
end

else --- If they dont own pass
	while true do
		wait(60)
	    ---Add only 1 to time leadstats
	end
end

--- Leaderstats - "Overall Time (Min)"

Also if there’s a better way to do this that would be nice.

local gmpsID = 15484617
local WaitTime = 0
	
if "Make it check if player has pass" then
	WaitTime  = 12
else --- If they dont own pass
	WaitTime = 60
end

spawn(function()
    whille true do
        wait(WaitTime)
        ---Add only 1 to time leadstats
    end
end)
--- Leaderstats - "Overall Time (Min)"
1 Like

Can you make it check if they have pass and add to leaderstats?

I cant seem to do that

I am not familiar with the MarketPlace Service so I don’t really know how to do that.

1 Like

You can use the MarketplaceService to check if a player owns a gamepass. I have also showed in the example below how to add a value to the leaderstats. You can combine this with a while loop if you wish.

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassId = 15484617

game.Players.PlayerAdded:Connect(function(player)
    if MarketplaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) then
        -- do whatever you want here
        player.leaderstats.Time.Value += 1 -- change Time to whatever the value in leaderstats is called
    end
end)
2 Likes

Can you make the script add to leaderstats?

local gmpsID = 15484617
local WaitTime = 0

if MarketplaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) then
	WaitTime  = 12
else --- If they dont own pass
	WaitTime = 60
end

spawn(function()
	while true do
		wait(WaitTime)
		player.leaderstats.Time.Value += 1
	end
end)

Script does not work

It underlines player and MarketPlaceService

You have to set those variables

Which variables?

Where in the script?

Player will not be defined if this is a server-sided script, which it should be as handling updating of leaderstats should be done on the server. You’re running into the issue with MarketplaceService underlining red as you have not defined the service. These variables need to be set properly for this to work.

One way you can set these values is by putting this inside a PlayerAdded event to know who the player is, and the full code can be seen below.

local MarketplaceService = game:GetService("MarketplaceService")
local gmpsID = 15484617

game.Players.PlayerAdded:Connect(function(player)
    local waitTime
    if MarketplaceService:UserOwnsGamePassAsync(player.UserId,gmpsID) then
    	waitTime  = 12
    else --- If they dont own pass
    	waitTime = 60
    end

    spawn(function()
    	while true do
    		player.leaderstats.Time.Value += 1
            wait(waitTime)
    	end
    end)
end)
1 Like
local MarketplaceService = game:GetService("MarketplaceService")
local gmpsID = 15484617

game.Players.PlayerAdded:Connect(function(player)
	local waitTime = 0
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) then
		waitTime  = 12
	else --- If they dont own pass
		waitTime = 60
	end

	spawn(function()
		while true do
			player.leaderstats.Time.Value += 1
			wait(waitTime)
		end
	end)
end)

Still seems to not have worked

I have updated the script I sent above; I accidentally defined gamepassId wrong in the MarketplaceService:UserOwnsGamePassAsync() line. Apologies for that.