I am reasonably new to scripting and I am working on a game but I need help making a gamepass that in-game gives you a piece of gear.
Thanks in advanced
I am reasonably new to scripting and I am working on a game but I need help making a gamepass that in-game gives you a piece of gear.
Thanks in advanced
You would need to use a Markpetplace service to check if the user owns the asset Id.
For example if your storing the âgearâ in the ServerStorage it will go something like thisâŚ
game.Players.PlayerAdded:connect(function(player)
local mkps = game:GetService("MarketplaceService")
local ss = game.ServerStorage
repeat wait(0.1) until player.Backpack
repeat wait(0.1) until player.StarterGear
if mkps:UserOwnsGamePassAsync(player.UserId, GAMEPASSID) then
ss.Sword:Clone().Parent = player.Backpack
ss.Sword:Clone().Parent = player.StarterGear
end
end)
For future reference show what you have done already therefore we can help.
THANK YOU SO MUCH. I have seen millions (exaggeration) of youtube tutorials but all of them are outdated.
And this is myfirst scripting post so I didnt know.
Thanks again
No problem, if you ever need help again go to the Developer Hub
for example for this perticular topic you would go to the Developer Hub and look up gamepasses
and it would show this Passes | Documentation - Roblox Creator Hub
Then once your stuck from tutorials come to here.
Please use Instance:WaitForChild(Child Name)
not repeat, this is just really inefficient
It takes 0 seconds if the object already exists
using repeat wait() until condition end
is a really bad practise and should be shunned upon
What is the child name?
I need thirty characters
An example of WaitForChild:
local PlayerGui = Player:WaitForChild("PlayerGui") --child name is the name of the instance you wish to wait for
It doesnât seem to work this is my code. I may have gone wrong.
game.Players.PlayerAdded:connect(function(player)
local mkps = game:GetService(âMarketplaceServiceâ)
local ss = game.ServerStorage
local PlayerGui = Player:WaitForChild(âPlayerGuiâ) --child name is the name of the instance you wish to wait for
if mkps:UserOwnsGamePassAsync(player.UserId, 9141220) then
ss.Sniper3:Clone().Parent = player.Backpack
ss.Sniper3:Clone().Parent = player.StarterGear
end
end)
The Player is defined as player
in your PlayerAdded event. You are referring to the Player as Player
in the :WaitForChild() line, giving you an error as Player
is returning nil. Pay attention to capitalization!
Fixed code:
local PlayerGui = player:WaitForChild(âPlayerGuiâ)