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

How do I make it so when the player dies they receive the gamepass weapon again after they respawn?

Asked by 3 years ago

So pretty much I want the player to get the gamepass weapon after they died and respawn they recieve it again. Here is the code I have so far. So under StarterGUI and then under ScreenGUI I added image button then a Local Script as follows:

script.Parent.MouseButton1Click:Connect(function()
    game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,17070852)
end)

The code above is supposed to make a image button and then if the player clicks on it they get a prompt to buy the gamepass weapon. So then in order for them to recieve the gamepass item. I added some other stuff. Under StarterGUI I added a Local Script that says:

local player = game.Players.LocalPlayer
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,17070852)

if ownsGamepass then
    local Launcher = game:GetService("ReplicatedStorage"):WaitForChild("Launcher"):Clone()
    Launcher.Parent = player.Backpack
end

So this is supposed to give the player the gamepass weapon but the thing is every time they die and respawn they lose the weapon. I want to make it so every time they respawn they receive the gamepass weapon again... Can someone make a script or edit this script for me? Or at least help me do so?

Very much appreciated!

1 answer

Log in to vote
0
Answered by 3 years ago

whenever someone's character is added, check if they have the gamepass, and give it to them if they do (in a server script)

game:GetService("Players").PlayerAdded:Connect(function(player) -- player joins the game for the first time
    player.CharacterAdded:Connect(function(character) -- whenever the player spawns or respawns, this is fired
        local ownsGamepass =                game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,17070852)

    if ownsGamepass then
            local Launcher = game:GetService("ReplicatedStorage"):WaitForChild("Launcher"):Clone()
            Launcher.Parent = player.Backpack
        end
    end)
end)
0
The player on the 2nd line is error. player.CharacterAdded:Connect that part. Only player is error... Please tell me why? AshsmithTube 15 — 3y
0
Oh nevermind that was my error. I copied it wrong! Thank you! Your answer is amazing! Let me try now! AshsmithTube 15 — 3y
0
It worked!!! :D AshsmithTube 15 — 3y
Ad

Answer this question