Hey guys, how would I make this code run smoother and more reliably? It doesn’t always give the tool as soon as they buy so they need to rejoin to get occasionally.
local MarketplaceService = game:GetService("MarketplaceService")
local SpeedCoil = 17930916
local GravityCoil = 17930931
local EpicSword = 18079239 --fill
game.Players.PlayerAdded:Connect(function(player)
print("Player added")
if MarketplaceService:UserOwnsGamePassAsync(player.UserId , GravityCoil) then
print("Gravity coil given")
game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
end
if MarketplaceService:UserOwnsGamePassAsync(player.UserId , SpeedCoil) then
print("Speed coil given")
game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
end
if MarketplaceService:UserOwnsGamePassAsync(player.UserId , EpicSword) then
print("Epic sword given")
game.ServerStorage.EpicSword:Clone().Parent = player.Backpack
game.ServerStorage.EpicSword:Clone().Parent = player.StarterGear
end
end)
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true then
if purchasedPassID == SpeedCoil then
game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
elseif purchasedPassID == GravityCoil then
game.ServerStorage.GravityCoil:Clone().Parent = player.Backpack
game.ServerStorage.GravityCoil:Clone().Parent = player.StarterGear
elseif purchasedPassID == EpicSword then
game.ServerStorage.EpicSword:Clone().Parent = player.Backpack
game.ServerStorage.EpicSword:Clone().Parent = player.StarterGear
end
end
end
-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
Thanks