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

Why Is This Script That Gives Gamepasses Only Give The Items When The Player Leaves And Rejoins?

Asked by 3 years ago

I have a script that is supposed to give gamepasses when the player clicks a button.

(local button script)

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

(gamepass giving script, in workspace)

local MarketPlaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)

    if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 15413257) then

        game.ServerStorage.Tools.SpeedCoil:Clone().Parent = player:WaitForChild("Backpack")
        game.ServerStorage.Tools.SpeedCoil:Clone().Parent = player:WaitForChild("StarterGear")
    end
end)

The scripts work but the gamepass giving script only gives the speed coil when the player rejoins the game, but I want it to give the weapon to the player instantly. (Putting the speed coil in replicated storage breaks the speed coil.) Please help.

Thank you!

1 answer

Log in to vote
1
Answered by 3 years ago

Players.PlayerAdded only fires when the player joins for the first time. If you want the coil to clone to the player's backpack every time they spawn, you can use the player's CharacterAdded property

local MarketPlaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, 15413257) then
        game.ServerStorage.Tools.SpeedCoil:Clone().Parent = player:WaitForChild("Backpack")
        end
    end)
end)
Ad

Answer this question