Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why my gamepass's tool dispears when I respawn my character ?

Asked by 4 years ago

Hello everyone, so I don't understand why my gamepass's tool dispears when I respawn my character. When I join my game, my tool appears but when I die, nothing. Why ? My script in ServerScriptService:

local Gid = 7835473
local mps = game:GetService("MarketplaceService")
print(12)

game.Players.PlayerAdded:Connect(function(player)
    print(1)
    if mps:UserOwnsGamePassAsync(player.UserId, Gid) then
        print(2)
        game.ServerStorage.AdminCard:Clone().Parent = player:WaitForChild("Backpack")



    end
end)

game.ReplicatedStorage.Give.OnServerEvent:Connect(function(player)
    print(3)
    game.ServerStorage.AdminCard:Clone().Parent = player:WaitForChild("Backpack")
end)

My another script in my GUI:

local mps = game:GetService("MarketplaceService")
local id = 7835473

script.Parent.MouseButton1Click:Connect(function()
    local player = game.Players.LocalPlayer
    mps:PromptGamePassPurchase(player, id)
end)

mps.PromptGamePassPurchaseFinished:Connect(function(player, idG, purchased)
    if idG == id and purchased then
        game.ReplicatedStorage.Give:FireServer()
    end
end)

Thank you in advance !

0
You have to put it on StarterGear if its a object. And if you want to save it, you need to know how to use DataStore. Let me know if you want a script explaining you how to do it. c: Foxy_Developer 111 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Ok... Lets try it!

First Step : First of all we need to know what is the "Market Place" service on Roblox API so we can get the Gamepass.

Link : [https://developer.roblox.com/en-us/api-reference/class/MarketplaceService]

Second Step : Second, we need to know how to access to a player that owns the Gamepass, but first we need the ID of the Gamepass. [You can get it by going to your gamepass page and looking for the URL, then you will see some numbers. That's the ID of your gamepass.]


--> The locals <-- local iD = 7835473 local mP = game:GetService("MarketplaceService")

That's how we acces to the Service and store the ID on a variable! So lets now fix your code!

Third Step : Enjoy coding! You always have to enjoy what are you doing! Play some music while you script or even play a game before to relax yourself.

Lets get into code

--> Locals <--

local id = 7835473
local marketplace = game:GetService("MarketplaceService")
local RS = game:GetService("ReplicatedStorage")
local tool = RS:WaitForChild("Tool") --> Change it to your tool name

--> Code <--

game.Players.PlayerAdded:Connect(function(player)
    if mp:UserOwnsGamePassAsync(player.UserId,Gid) then
    print("We are ok")

    local clone1 = tool:Clone()
    local clone2 = tool:Clone()

    --> Lets give them a parent <--

    local starterGear = player:WaitForChild("StarterGear")
    clone1.Parent = player.Backpack
    clone2.Parent = starterGear
end

local warnMessage = "The code is incorrect!"
pcall(warnMessage)

That's how you fix it easealy. There's a bug so before you can't acces to the StarterGear like normaly we did it. So now is kinda fixed.

I hope my answer already solved your question. If its like that, please accept my answer. So you can let me know this helps you!

Note : The edit are for grammatical errors.

Keep scripting!

0
I thought StarterGear was deprecated St_vnC 330 — 4y
0
Yeah, but now you can acces to the StaterGear with a WaitForChild function Foxy_Developer 111 — 4y
Ad

Answer this question