Hello there! I have a game where you can be a Jedi. I have decided to make a gamepass that gives a better tool for the force. However, you won’t get the tool till you rejoin once. It’s happens several times. There isn’t any errors in the output. Help needed!
Script:
local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
game.Players.PlayerAdded:Connect(function(player)
local has_pass = mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID)
player.CharacterAdded:Connect(function()
if has_pass then
tool:Clone().Parent = player.Backpack
end
end)
end)
Put the tool in StarterGear instead of backpack. This will keep it during respawns.
local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
game.Players.PlayerAdded:Connect(function(player)
local has_pass = mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID)
if has_pass then
local starterGear = player:WaitForChild("StarterGear")
tool:Clone().Parent = starterGear
end
end)
Oh sorry. Then you must make sure to put the tool in the player’s starter gear and backpack if the purchase was successful. You need to add this to the code where you buy the gamepass.
EDIT: The code shown in that case is completely irrelevant as that only runs when the player joins, not when they buy the gamepass.
Was just about to reply in regards to this after reading over your code. You accidentally forgot to also clone the tool into the player’s backpack.
local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
game.Players.PlayerAdded:Connect(function(player)
local has_pass = mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID)
if has_pass then
local starterGear = player:WaitForChild("StarterGear")
tool:Clone().Parent = starterGear
tool:Clone().Parent = player.Backpack -- this is what you forgot to add
end
end)
I understand that. I don’t understand how it solves the problem of giving the tool before rejoining. Since that would need to be given when the gamepass is bought. Anyways, the op seems to have solved their problem so all good!
This is just a tip. You should, keep a value inside of the player for game pass info, like a Bool Value (true or false) which is called like, OwnsJediGamepass, and you can even do some data store trickery with it, so that people cant delete it from their inventory. That makes game passes easier to use. And if you have a data store system, you can gift players gamepasses. And also have gamepasses update right away when you buy them.
local mps = game:GetService("MarketplaceService")
local gamepass_ID = 13469027
local tool = game.ServerStorage["master jedi force"]
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if mps:UserOwnsGamePassAsync(player.UserId, gamepass_ID) then
tool:Clone().Parent = player.Backpack
end
end)
end)
This fixes it with the player having to re-join too get the gamepass only now having to
reset their character for the gamepass to load