You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want my Medkit to be in the inventory of the people who bought it and for it to work.
What is the issue? Include screenshots / videos if possible!
Somehow my screengui is blocking it from working because everytime I get rid of it, it works. I have no idea how it is because it is a ScreenGui for a leave button. Yet, it works everytime in studio when I Gui is there.
(Code will be at the end).
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked around but could not find anything, and I tried random stuff but nothing worked.
Code for getting the Medkit
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
Players.PlayerAdded:Connect(function(player)
wait()
local ownsGamepass = MarketplaceService:UserOwnsGamePassAsync(player.UserId,20791449)
if ownsGamepass then
local Medkit = ReplicatedStorage:WaitForChild(“Medkit”):Clone()
Medkit.Parent = player.Backpack
end
end)
– I suggest storing this script inside ServerScriptService or Workspace
– Sorry about it not working earlier, V2
local Id = 20381983 – Put the gamepass id here, it is found in the url and is the number part
local VipPlayers = {""} – Any person’s name put here will get the gamepass for free
local ToolName = {“Put your tool name here”} – Put the name of your tool here that MUST be stored in ServerStorage
local function FindPlayer(Plr)
for Num, Pler in pairs(VipPlayers) do
if Pler == Plr then
return true
end
end
end
game.Players.PlayerAdded:connect(function(Player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.UserId, Id) or FindPlayer(Player.Name) then
Player.CharacterAdded:Connect(function(character)
for Num, Tool in pairs(ToolName) do
if game:GetService(“ServerStorage”):FindFirstChild(Tool) then
game:GetService(“ServerStorage”)[Tool]:Clone().Parent = Player.Backpack
end
end
end)
for Num, Tool in pairs(ToolName) do
if Player.Backpack:FindFirstChild(Tool) == nil then
if game:GetService("ServerStorage"):FindFirstChild(Tool) then
game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
end
end
end
end
Howdy! I am here to help you with this problem. Go to ServerScriptService, make a script, add the medkit to the script, and paste the following code in:
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassId = --YOUR ID
local Tool = script.ToolName
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
end)