How to keep the gear in StarterPack after reset?

What do you want to achieve?
I have a gamepass that gives the gear to the player directly upon purchase, the problem is after the player resets the gear is no longer inside the player’s startpack? How can I achieve that?

Script Inside ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "GiveItemEvent"
remoteEvent.Parent = ReplicatedStorage

local gearName = "SnowmanSword" -- gear

local function giveItemToPlayer(player)
    local character = player.Character or player.CharacterAdded:Wait()

    -- Get the gear from ServerStorage
    local gear = ServerStorage:FindFirstChild(gearName)

    if gear then
        -- Clone the gear and parent it to the player's character
        local gearClone = gear:Clone()
        gearClone.Parent = character
    else
        warn("Gear not found in ServerStorage.")
    end
end

remoteEvent.OnServerEvent:Connect(function(player)
    giveItemToPlayer(player)
    print("Item given to player:", player.Name)
end)

Any help or suggestions are appreciated, thanks! :slight_smile:

1 Like

Can I see the local script where the remote event is being fired? Also is the script working and needs additions like checking if the player has the game pass, or isn’t working and is getting an error?

1 Like

I wouldn’t recommend using remotes for that as exploiters can abuse it to get gamepass gears for free (unless you add proper checks), instead connect it to characteradded event which checks if player owns a gamepass and then give the tool to them

You simply have to clone the gear into the player’s StarterGear

1 Like
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local gamepassId = 12913649 -- Replace this with your actual GamePass ID
local remoteEvent = game.ReplicatedStorage:WaitForChild("GiveItemEvent") 

local player = Players.LocalPlayer

local function giveItemToPlayer()
	remoteEvent:FireServer(player)
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, id)
	-- Check if the purchased game pass ID matches the expected game pass ID
	if id == gamepassId then
		giveItemToPlayer()
		print("Item request sent to the server.")
	end
end)

-- Connect a button click event to prompt the purchase
script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptGamePassPurchase(player, gamepassId)
end)

When players join game, check if they has your gamepasses, store that in a server table, and from server clone the item you wanna give to them.
Obviously keep giving the item upon player buy the gamepass, and store their IDs into the table too.
You will use that table so evertime a player dies you can give them the item again

1 Like

You can use if not MarketplaceService:UserOwnsGamePassAsync(player.UserId, passId) then return end at the top of the giveItemToPlayer function to check if they own the gamepass. Of course you also need to define MarketplaceService and passId.

1 Like

I completely agree with what @Aqua_Turneur and @Dev_Peashie stated.

When the player logs in, check for what gamepasses they have and place the results in a server table.
So every time the player’s character model spawns in game, check the table. If they have the item, then clone it into their backpack.

1 Like

Remember that you must keep their cloned tools to StarterGear. When player resets their Backpack folder clears completely, but if you put the cloned tool in player’s starter gear, they won’t lose it. The function would be this:

local function giveItemToPlayer(player)
    local character = player.Character or player.CharacterAdded:Wait()

    -- Get the gear from ServerStorage
    local gear = ServerStorage:FindFirstChild(gearName)

    if gear then
        -- Clone the gear and parent it to the player's character
        local gearClone = gear:Clone()
        gearClone.Parent = character

-- Cloning the gear a second time to save it in StarterGear, this doesn't immediately give the tool to your characters, that's why I kept your other gear clone()
        local savedGear = gear:Clone()
        savedGear.Parent = player.StarterGear
    else
        warn("Gear not found in ServerStorage.")
    end
end
2 Likes

This finally was the key for it to work. Been literally trying to get this working all day, thanks everyone for the help truly

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.