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

I am so confused with this MarketplaceService Help?

I am making a speed gamepass script and found the gamepass script form roblox Developer Hub https://developer.roblox.com/en-us/articles/Game-Passes-One-Time-Purchases so i edited it for my needs to make the speed go faster but for some reason it never notices when the players character is added.

I'll show you what I did.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local SpeedPassID = 6810819  -- Change this to your game pass ID
 
Players.PlayerAdded:Connect(function(plr)
 
	local hasSpeedPass = false
 
	-- Check if the player already owns the game pass
	local success, message = pcall(function()
		hasSpeedPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, SpeedPassID)
	end)
 
	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))--this never prints 
		return
	end
 
	if hasSpeedPass == true then
		print(plr.Name .. " owns the game pass with ID " .. SpeedPassID)--this always prints
		
		plr.CharacterAdded:Connect(function(char)--broken?
			print("Test")-- this never prints
		end)
	
	end
end)
 

why is this not working and how can i fix?

1 answer

I fixed it myself: like this instead

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local SpeedPassID = 6810819  -- Change this to your game pass ID
 
Players.PlayerAdded:Connect(function(plr)
	
	plr.CharacterAdded:Connect(function(char)--broken?

 
		local hasSpeedPass = false
	 
		-- Check if the player already owns the game pass
		local success, message = pcall(function()
			hasSpeedPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, SpeedPassID)
		end)
	 
		-- If there's an error, issue a warning and exit the function
		if not success then
			warn("Error while checking if player has pass: " .. tostring(message))--this never prints 
			return
		end
	 
		if hasSpeedPass == true then
			print(plr.Name .. " owns the game pass with ID " .. SpeedPassID)--this always prints
			local hum = char:FindFirstChildOfClass("Humanoid")
			if hum then
				hum.WalkSpeed = 32
			end
			
		end
	end)
end)

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