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

How to make a gamepass that makes the player start with 1500 points?

I made a gamepass that gives the player 1500 points when joining but when i test it it stays at 500 points and doesn't give me a error or anything

local MarketplaceService = game:GetService("MarketplaceService")
function onPlayerEntered(newPlayer)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local score = Instance.new("IntValue")
	
	score.Name = "Points"
	score.Value = 500

	score.Parent = stats	
	stats.Parent = newPlayer
	if MarketplaceService:PlayerOwnsAsset(newPlayer, 15884145) then
		score.Value = 1500
	end
	while true do
		wait(60)
		score.Value = score.Value + 15
	end
end

game.Players.ChildAdded:connect(onPlayerEntered)

2 answers

✓ Accepted answer

Try using MarketplaceService:UserOwnsGamePassAsync(playerUserId,gamePassId) instead. Also instead of childAdded use .PlayerAdded

You made a typo with game.Players.ChildAdded:conenct(onPlayerEntered)

It should be game.Players.ChildAdded:Connect(onPlayerEntered)


Also make sure to wrap in pcall() and use UserOwnsGamePassAsync, along with using booleans.

Hello, i haven't tested this code out, but everything should work fine :)

If there's any problems, please @ me and let me know if anything's wrong.

local MarketPlaceService = game:GetService("MarketplaceService")

function onPlayerEntered(newPlayer)
	
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	
	local score = Instance.new("IntValue")
	
	score.Name = "Points"
	
	score.Parent = stats
	stats.Parent = newPlayer
	
	local hasPass = false -- Creating a boolean to use for to check if the player owns the gamepass
	
	-- Wrapping this in a pcall isn't necessary, but if roblox's servers shutdown or something, then the script won't break.
	
	local success, errormessage = pcall(function()
		hasPass = MarketPlaceService:UserOwnsGamePassAsync(newPlayer.UserId, 15884145) -- This essentially is setting this boolean to false or true depending on if the player has the gamepass
	end)
	
	if hasPass then  --|| The player ownes the gamepass
		
		score.Value = 1500
		
	else if not hasPass then --|| The player doesn't own the gamepass
			
			score.Value = 500
			
			
		end	
		
		while wait(60) do
			
			score.Value += 15 --|| Does the same thing as score.Value = score.Value + 15, you should get used to using this syntax
			
		end
		
	end
end

game.Players.PlayerAdded:Connect(onPlayerEntered) --|| Using PlayerAdded is more efficient

3 comments

0

I made a mistake on else if not hasPass statement, it should be "else".

0

:connect is just a deprecated version of :Connect

0

:connect still works

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