#In market place service

1 messages · Page 1 of 1 (latest)

unreal leaf
#

How to prevent person buy more than 1 time?

local part = script.Parent
local marketplaceservice = game:GetService("MarketplaceService")
local VipId = 1235582640
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("Tool")

local function givethings(player)
    

    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char:FindFirstChild("Humanoid")
    hum.WalkSpeed = 32
    
    local newsword = sword:Clone()
    local BackPack = player:FindFirstChild("Backpack")
    newsword.Parent = BackPack
    
    player.CharacterAdded:Connect(function(charcter)
        task.wait(2)
        local humanoid = charcter:WaitForChild("Humanoid")
        local newsword_spawn = sword:Clone()
        local BackPack = player:WaitForChild("Backpack")
        if humanoid and BackPack then
            humanoid.WalkSpeed = 32
            newsword_spawn.Parent = BackPack
        end
        
    end)
    
end

marketplaceservice.PromptGamePassPurchaseFinished:Connect(function(player , gamepassid , purched)
    if gamepassid == VipId and purched then
        givethings(player)
    end
end)

part.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    
    if plr then
        
        pcall(function()
            marketplaceservice:PromptGamePassPurchase(plr , VipId)
        end)        
    end
end)
safe smelt
unreal leaf
#

like i keep buying it and get many tools

balmy kite
#

DEV Product is multiple purchases

#

Gamepass is once

#

And owned

unreal leaf
unreal leaf
balmy kite
#

Let me read script

unreal leaf
balmy kite
#

Ok what’s the problem

unreal leaf
balmy kite
#

Im Studio?

unreal leaf
#

yeah

balmy kite
#

In*

#

Yes that’s normal

unreal leaf
#

?

#

bec i delete my gamepass in inv u mean ?

balmy kite
#

No

#

Even if u don’t

#

It’s Roblox studio

#

It’s a testing purchase

unreal leaf
#

ohh

balmy kite
#

But in real game u can buy only once

#

Ur script is fine

#

It’s Roblox studio

unreal leaf
#

ok but how i know if code is working ?

balmy kite
#

Arent u getting the sword?

unreal leaf
balmy kite
#

And error?

unreal leaf
#

no

balmy kite
#

Ok wait

unreal leaf
#

Ok

balmy kite
#

I think its bc of character added

#

Cuz if u fire

#

The script waits until the character is added

#

But since the character is already added it won’t work

unreal leaf
#

what u mean ?

balmy kite
#

Look

#

In ur script

#

Givethings

#

You are using characterAdded

#

And this will only work when u reset

unreal leaf
#

i say in function givereward()
it will give it first tool
and if he charcter reset will give it too

balmy kite
#

Ok wait

#

I didn’t see

unreal leaf
#

okk

balmy kite
#

When u fire the script

#

Is ur humanoid WalkSpeed

#

36?

#

Or normal

unreal leaf
#

u mean when i buy gamepass ?

balmy kite
#

Yes

unreal leaf
#

yes change 36

#

and give me tool

balmy kite
#

Ok

#

But when reset?

unreal leaf
#

also when i reset

balmy kite
#

So u get sword

unreal leaf
balmy kite
#

Ok what is the problem then?

unreal leaf
#

but u sayed to me tysm

balmy kite
#

You can test in real game

#

I can test

unreal leaf
#

oh 1 more thing

balmy kite
#

Put gamepass price to 5

#

I can buy and test

unreal leaf
balmy kite
#

Ok

unreal leaf
#

this script also will work fine ?

#
local MarketplaceService = game:GetService("MarketplaceService")
local VipId = 1235582640
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(charcter)
        local ReplicatedStorage = game:GetService("ReplicatedStorage")
        local humanoid = charcter:FindFirstChild("Humanoid")
        local success , haspass = pcall(function()
            return MarketplaceService:UserOwnsGamePassAsync(plr.UserId , VipId)
        end)

        if success and haspass then
            local sword = ReplicatedStorage:WaitForChild("Tool")
            local newsword = sword:Clone()
            local BackPack = plr:FindFirstChild("Backpack")
            newsword.Parent =  BackPack
            humanoid.WalkSpeed = 32
        end
    end)
    
end)
#

this to check if plr already has gamepass

#

bec i cant test it

balmy kite
#

Ok

#

Wait

#

Yes it’s good

main lava
#

Why do you check it every time you add a char, it would be better to just use some bool, then update it once the player buys it (then just only check onPlayerAdded)

unreal leaf
unreal leaf
main lava
#

The one you've send 2 minutes ago

balmy kite
#

Oh yeah

#

Right

#

Instead of character added

#

U can put it in playeradded

#

Bc the script checks it once and doesn’t repeat

#

Bc if u reset character the script will check again and that’s useless

unreal leaf
#

but like this when i reset charcter the tools will disappear

balmy kite
#

No

#

Wait

#

I write it for u so u understand

unreal leaf
#

ok ty

balmy kite
#

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local VipId = 1235582640
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
           local humanoid = char:FindFirstChild("Humanoid")
        local success , haspass = pcall(function()
            return MarketplaceService:UserOwnsGamePassAsync(plr.UserId , VipId)
        end)
plr.CharacterAdded:Connect(function(charcter)
       

        if success and haspass then
            local sword = ReplicatedStorage:WaitForChild("Tool")
            local newsword = sword:Clone()
            local BackPack = plr:FindFirstChild("Backpack")
            newsword.Parent =  BackPack
            humanoid.WalkSpeed = 32
        end
    end)
    
end)
#

So

#

Instead that pcall is inside characterAdded

#

U put it in playeradded

#

Bc the pcall will check it once

unreal leaf
#

ohh

#

right how i forgot this

balmy kite
#

But if it’s in character the pcall will always check if player owns

#

Yes

unreal leaf
#

ok let me see the script

#

why u add this line , i can just say player.charcteradded

#

hum = charcter:waitforchiled...

balmy kite
#

Where

unreal leaf
balmy kite
#

I did this on phone

#

Ok wait

#

Oh yeah

#

U can change

unreal leaf
balmy kite
#

It was hard doing it cuz on phone it’s all almost unreadable

balmy kite
#

Ye ok u can remove that like

#

Line

unreal leaf
#
local MarketplaceService = game:GetService("MarketplaceService")
local VipId = 1235582640
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("Tool")

game.Players.PlayerAdded:Connect(function(plr)
    local success , haspass = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(plr.UserId , VipId)
    end)
    plr.CharacterAdded:Connect(function(charcter)
        local humanoid = charcter:WaitForChild("Humanoid")
        if success and haspass then
            local newsword = sword:Clone()
            local BackPack = plr:WaitForChild("Backpack")
            newsword.Parent =  BackPack
            humanoid.WalkSpeed = 32
        end
    end)
    
end)
```here is last thing
#

all work well ?

balmy kite
#

Instead use the character from characterAdded

main lava
balmy kite
#

Yes

unreal leaf
#

@balmy kite one last thing i want to know
i use pcall in gamepassown and buy gamepass

main lava
#

It technically shouldn't break anything. But it's a check to see if the pcall went successfully. And no need to check that for every single character, just for every player should be plenty

unreal leaf
#

but not gamepass finish right ?

balmy kite
#

Right

#

U can put the if succes and hasbadge above characterAdded

unreal leaf
balmy kite
#

U need if lol

#

It’s just that u don’t repeat all the time

unreal leaf
unreal leaf
balmy kite
#

Gamepass finished is a event

unreal leaf
#
local MarketplaceService = game:GetService("MarketplaceService")
local VipId = 1235582640
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("Tool")

game.Players.PlayerAdded:Connect(function(plr)
    local success , haspass = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(plr.UserId , VipId)
    end)
    
    if success and haspass then
        local char = plr.Character or plr.CharacterAdded:Wait()
        local hum = char:WaitForChild("Humanoid")
        local BackPack = plr:WaitForChild("Backpack")

        hum.WalkSpeed = 32
        local nsowrd = sword:Clone()
        nsowrd.Parent = BackPack
        
        
        plr.CharacterAdded:Connect(function(charcter)
            local humanoid = charcter:WaitForChild("Humanoid")
            if success and haspass then
                local newsword = sword:Clone()
                local BackPack = plr:WaitForChild("Backpack")
                newsword.Parent =  BackPack
                humanoid.WalkSpeed = 32
            end
        end)
    end
    
    
end)
unreal leaf
balmy kite
#

Why u have twice character added lol

#

OH NVM

#

I MISSRESD

#

MISS read

unreal leaf
lapis juniperBOT
#

studio** You are now Level 18! **studio

unreal leaf
balmy kite
#

Yes

#

Script is ready

unreal leaf
#

yess

balmy kite
#

Only gamepasspurchase

unreal leaf
balmy kite
#

Bc it’s a method

#

And Game pass finished is a event

#

Event doesn’t need pcall

#

Method only

#

Method is with :

#

And event .

balmy kite
unreal leaf
balmy kite
#

yes

#

But no worries

#

Script is ok now

unreal leaf
#

okk now all thing work well

balmy kite
#

Ye

unreal leaf
balmy kite
#

If error tell me

balmy kite
unreal leaf
balmy kite
#

Ok

unreal leaf