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

Help with gamepass giver? (Item given on bought)

local mps = game:GetService("MarketplaceService")
local gamepass_id = 8946545

game.Players.PlayerAdded:Connect(function(player)
 	if mps:UserOwnsGamePassAsync(player.UserId, gamepass_id) then
 	 	game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
  		game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("StarterGear")
 	end
end)

game.ReplicatedStorage.Give.OnServerEvent:Connect(function(player)
	game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
  	game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("StarterGear")
end)

I want to make it so that if the gamepass is bought, Lemonaide Bleach will be inside of the players inventory forever. Please help!

2 answers

One thing I noticed about your script: You add the item to starter pack. This is not a good idea, as if it decides to actually put it in the starter pack, it will give it to all players on respawn. Instead, you just need make a connect on player reset function that checks if the player that that was just added has the gamepass, then gives the item to them. Heres the fixed script:

wait(2) --Keep at 2 for safety.

local gpid = 3333333333 --Change to your gamepass id

local mps = game:GetService("GamePassService") -- You need the gamepass service, not the marketplace service.
function respawned(char)
	player = game.Players:FindFirstChild(char.Name)
	print("Respawned")
	if char:FindFirstChild("Head") ~= nil then
		print("It's a Player!")
		if GPS:PlayerHasPass(player, gpid) then
			print("Has gamepass")
			game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player.Backpack
		else
			print("No gamepass")
		end
	end
end
game.Workspace.ChildAdded:connect(respawned)

5 comments

0

where do i put the gamepass id?

0

My man there isnt a gampass service

0

because i would think that the script wouldnt know which gamepass you are trying to reference.

0

Read my edited answer

0

also, there is a gamepass service

local mps = game:GetService("MarketplaceService")
local gamepass_id = 8946545

game.Players.PlayerAdded:Connect(function(player)
    if mps:UserOwnsGamePassAsync(player.UserId, gamepass_id) then
        game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
plr.CharacterAdded:Connect(function(Character)
		repeat wait() until plr.Character ~= nil	
		local player = game.Players:GetPlayerFromCharacter(Character)
		game.ServerStorage("Lemonaide Bleach"):Clone().Parent = player:WaitForChild("Backpack")
	end)
end)

Don't put the gear in the StarterPack, instead put it in the backpack when respawning.

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