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

How do I make this respawn gamepass work?

Asked by
tomr295 -1
4 years ago

I've made a gamepass that is supposed to make it so that when it's purchased you will get a faster respawn time, when it comes to marketplace scripts I'm not very good at them so could someone help me?

local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local id = 971827976    

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(chr)
        if MarketplaceService:UserOwnsGamePassAsync(player.UserId, id) then
            repeat wait() until chr.Humanoid
            chr.Humanoid.Died:Connect(function()
                wait(.3)
                plr:LoadCharacter()
        end)
    end
end)
0
I believe you cannot do :LoadCharacter() after a player has died. Someone correct me if i'm wrong. might wanna look into this https://developer.roblox.com/en-us/api-reference/property/Players/RespawnTime? proqrammed 285 — 4y
0
You actually can call :LoadCharacter() on a Player that has died. And that link only shows you how to modify the respawn time for all players, not an individual one, as this gamepass seeks to achieve. Rinpix 639 — 4y
0
Are you getting any errors when this script runs? Rinpix 639 — 4y

1 answer

Log in to vote
0
Answered by
p0vd 207 Moderation Voter
4 years ago
Edited 4 years ago

When using CharacterAdded event don't use the player variable.

local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local id = 971827976    

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(chr)
        if MarketplaceService:UserOwnsGamePassAsync(game.Players:FindFirstChild(chr.Name).UserId, id) then
            repeat wait() until chr.Humanoid
            chr.Humanoid.Died:Connect(function()
                wait(.3)
                plr:LoadCharacter()
           end)
        end
    end)
end)
0
Using the player variable is perfectly legitimate, why wouldn't it be? Rinpix 639 — 4y
0
i really dont know either I had same issue like this before but then I thought of another way to get the player by using the character's name and boom it worked. p0vd 207 — 4y
0
P0vd I got an error of tomr295 -1 — 4y
0
15:22:49.291 - ServerScriptService.Script:14: Expected 'end' (to close 'function' at line 5), got <eof> tomr295 -1 — 4y
View all comments (4 more)
0
i simply modified your code p0vd 207 — 4y
0
but here i fixed it should work now accept if it does p0vd 207 — 4y
0
Ok I'll try later I'm doing something right now: D tomr295 -1 — 4y
0
ok bruh i need you to accept it p0vd 207 — 4y
Ad

Answer this question