Please Help | How to Create GamePass shop with a equip and unequip

I’m trying to create a gamepass shop with trails and I was wondering if you their is a way to create a script to equip and unequip a trail. I looked all over the forum and youtube and found nothing. If this is in the wrong topic please tell me.

2 Likes

Clone the trail when equipping it and destroy it when dequipping it.

2 Likes

I have barley any experience with scripting, can you explain with more detail? Or send a link.

1 Like

Well, you’ll need to make a trail, and put it somewhere. I recommend usingServerStorage. Now you’ll also need a RemoteEvent to tell the server that you want to equip a trail. Then the server removes any current trail you have, and clones the one you want to equip to your character. This code should do just that.

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

local trailEvent = ReplicatedStorage.EquipTrail; --Make a RemoteEvent in ReplicatedStorage called "EquipTrail"
local trailsFolder = ServerStorage.Trails; --Make a folder in ServerStorage called "Trails"

local gamePassId = 0000000; --Change this to what your gamepass Id is

function equipTrail(plr, trailName)
	local character = plr.Character; --All players have a character assigned to them
	local hrp = character.PrimaryPart; --This is the character's humanoid rootpart, which we will parent the trails to
	local trail = trailsFolder:FindFirstChild(trailName); --Finds a trail with the given name
	
	if trail and MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamePassId) then --If the trail was found AND the player owns the gamepass
		local currentTrail = hrp:FindFirstChild("Trail"); --Attempts to find a trail that is already equipped
		if currentTrail then --If a trail was found, remove it
			currentTrail:Destroy();
		end
		
		trail = trail:Clone();
		trail.Name = "Trail"; --Names the trail so we can easily find it when dequipping it
		trail.Parent = hrp; --Parents the trail
	end
end
trailEvent.OnServerEvent:Connect(equipTrail);

Obviously you’ll need a LocalScript to fire the event, but I wasn’t sure how you wanted to go about it. I can also help with that if necessary.

1 Like

where do i place the script? In ServerScriptService? or something else

ServerScriptService would work.

1 Like

Okay, This is what did:


Do i need to do anything else now?

Now you need a LocalScript to fire the event when you want to equip a trail, which I wasn’t sure which you wanted to do. You could use a gui button to do this.

I was thinking of using a gui button, can you teach me what to put in the LocalScripts. Thank you for helping i will give you credit.

To detect when a gui button is clicked, you’ll use the .MouseButton1Down event, and then fire the remote event.

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

local trailEvent = ReplicatedStorage:WaitForChild("EquipTrail");

local button = --Assign the button to wherever it is here

button.MouseButton1Down:Connect(function()
    trailEvent:FireServer(button.Name); --You should name the button what the name of the trail is
end)
1 Like

what do i put in

local button =

Im not sure if this is correct. Can you tell me what I did wrong

SERVER//SCRIPT
You can place this in ServerScriptService.

--[[Credit: @JelliedBanana ]]--

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

local trailEvent = ReplicatedStorage.EquipTrail; --Make a RemoteEvent in ReplicatedStorage called "EquipTrail"
local trailsFolder = ServerStorage.Trails; --Make a folder in ServerStorage called "Trails"

local gamePassId = 0000000; --Change this to what your gamepass Id is

function equipTrail(plr, trailName)
	local character = plr.Character; --All players have a character assigned to them
	local hrp = character.PrimaryPart; --This is the character's humanoid rootpart, which we will parent the trails to
	local trail = trailsFolder:FindFirstChild(trailName); --Finds a trail with the given name
	
	if trail and MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gamePassId) then --If the trail was found AND the player owns the gamepass
		local currentTrail = hrp:FindFirstChild("Trail"); --Attempts to find a trail that is already equipped
		if currentTrail then --If a trail was found, remove it
			currentTrail:Destroy();
		end
		
		trail = trail:Clone();
		trail.Name = "Trail"; --Names the trail so we can easily find it when dequipping it
		trail.Parent = hrp; --Parents the trail
	end
end
trailEvent.OnServerEvent:Connect(equipTrail);

CLIENT//LOCALSCRIPT
This should be in a LocalScript, for you I’d recommend placing it in the StarterGui.

You can either build a gui in the StarterGui, or via script.

--[[Written by @JelliedBanana // Edited by @Prince_Duke]]--
 
local ReplicatedStorage = game:GetService("ReplicatedStorage");

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local trailEvent = ReplicatedStorage:WaitForChild("EquipTrail");

local Trail_Name = "TRAIL NAME HERE" -- We have the name of your trail here, instead of the button's name

--[[ I recommend you build your GUI. If you do:
local screengui = PlayerGui:WaitForChild("NAME OF SCREEN GUI HERE")
local button = screengui:WaitForChild("BUTTON NAME HERE") 
]]
local screengui = Instance.new("ScreenGui", PlayerGui)
local button =  Instance.new("TextButton", screengui) --Assign the button to wherever it is here
--button.Name = "NAME OF TRAIL HERE" 
button.TextScaled = true 
button.Text = "Trail"

button.MouseButton1Down:Connect(function()
    --trailEvent:FireServer(button.Name); 
    trailEvent:FireServer(Trail_Name);
end)

I am not a dedicated programmer so if you encounter any problems with this, please let me know and I will do my best to properly inform you!

1 Like

Not at all sure if this will help since I made it a while back but I thought I might as well mention it, I have a trail inventory model that checks for gamepasses and equips trails, though the instructions are kinda confusing. Hope this helps!

do i put the local script inside the button or just startergui?

can you send the model? Also can you equip and unequip the trail?