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

regiving a item, after respawn?

Asked by 4 years ago

this is what i got so far, and its working but there is just one problem whenever someone respawn they'll lose the item and are forced to rejoin and I also got 1 major flaw, that it sometimes doesn't run on flooded servers

01local MarketplaceService = game:GetService("MarketplaceService")
02local Players = game:GetService("Players")
03 
04local BoomboxID = 9595857
05 
06game.Players.PlayerAdded:Connect(function(player)
07    local success, message = pcall(function()
08        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, BoomboxID)
09        end)
10        if hasPass then
11            print("Player has the gamepass")
12 
13            local boombox = game.ReplicatedStorage.BoomBox:Clone()
14            boombox.Parent = player.Backpack
15 
View all 29 lines...

2 answers

Log in to vote
0
Answered by 4 years ago

I would use Player.CharacterAdded for this. It runs every time a character spawns in. Here is a video of an example.

I rewrote your code:

01local MarketplaceService = game:GetService("MarketplaceService")
02local Players = game:GetService("Players")
03local BoomboxID = 1087508 -- gamepassId
04 
05game.Players.PlayerAdded:Connect(function(player) --runs when a player joins the game
06    player.CharacterAdded:Connect(function() -- runs when a character spawns in
07    local hasPass
08    local success, messsage = pcall(function()
09        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, BoomboxID)
10        end)
11        if hasPass then
12            print(player.Name.." has the gamepass")
13            local boombox = game.ReplicatedStorage.BoomBox:Clone()
14            boombox.Parent = player.Backpack
15        end
View all 28 lines...
0
wow thanks for your fast response! thats exactly what i was looking for!! Ijeremyl 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

thanks for your response thats exactly what i was looking for! thankyou

Answer this question