Hello Developers!
I made a gamepass that when you bought it, you get extra speed and when ever the player resets or leaves the game, they won’t have the gamepass. How can I fix this? Any reply is deeply appreciated!
Hello Developers!
I made a gamepass that when you bought it, you get extra speed and when ever the player resets or leaves the game, they won’t have the gamepass. How can I fix this? Any reply is deeply appreciated!
I think in this case a Developer Product would be more suitable for what you’re wanting, as they can be bought more than once and their effects don’t persist when you reset or leave.
I would recommend doing a bit of research via the Developer Products Dev Wiki Page
Yeah, but I saw the devking do it, it’s just that I don’t understand what he’s doing.
Wait do you mean when the player resets or leaves the gamepass stops working for them? You can make it so if the player resets or rejoins, you check if they own the gamepass through UserOwnsGamePassAsync. This function checks if the user has the specified gamepass and if they do, do something
No, I mean when the player buys the gamepass then leaves or resets, they have to buy the gamepass again.
In your case, you’re either using a developer product, or your gamepass script is probably just in the ProcessReciept or something. I’d suggest making a check if player has the gamepass upon character-adding and then if they do, award them the perks.
local gamepassId = 0 -- Your gamepass ID
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamepassId) then
-- Perks
end
end)
end)
Oh, I’m not sure how that’s possible, it’s better if you just use Developer Products than try to find a method to do that with gamepasses, it’ll save you the hassle
You can’t just buy a gamepass again. That would be a Developer Product.
Wait I’m confusing myself. You were right… I meant that whenever the player resets or leaves, the gamepass just stops working for them.
Then like I mentioned, you use UserOwnsGamePassAsync. This checks if the specified player i nthe first parameter has the gamepass with the id in the second parameter. An example would be like how @0V_ex provided,
local gamepassId = 0 -- Your gamepass ID
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamepassId) then
-- Perks
end
end)
end)
You could hook it up like so and if the player has that gamepass with the id you give, it’ll run whatever is inside the if statement. So what you could do is write something like that, change some values around, and inside the if statement, copy what is meant to happen when someone has the gamepass there
That code doesn’t account for players that are already in game when the script runs, and their character might have already been added before the CharacterAdded event runs.
Here’s a way to be extra secure:
local Players = game:GetService('Players')
local MarketplaceService = game:GetService('MarketplaceService')
local GamePassId = 00000
local GamePassWalkSpeed = 50
local function PlayerAdded(Player)
local function CharacterAdded(Character)
local Check = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamePassId)
if Check == false then return end
local Humanoid = Character:FindFirstChild('Humanoid')
if Humanoid == nil then return end
Humanoid.WalkSpeed = GamePassWalkSpeed
end
local Character = Player.Character
if Character == true then
coroutine.resume(coroutine.create(function()
CharacterAdded(Character)
end))
end
Player.CharacterAdded:Connect(CharacterAdded)
end
-- Loop through existing players
local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
local Player = GetPlayers[i]
coroutine.resume(coroutine.create(function()
PlayerAdded(Player)
end))
end
Players.PlayerAdded:Connect(PlayerAdded)