local Gamepass = 703428408
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
repeat task.wait() until Character.Humanoid
Character.Humanoid.Died:connect(function()
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, Gamepass) then
Player:LoadCharacter()
end
end)
end)
end)
anyone know why this isn’t working and if you do can you help me fix it so that it does? correct person gets solution
it should since you do the check every time the player dies . however, this method is kinda expensive for the performance and i would recommend checking if the player own the gamepass and if yes , then detect if the player dies
like this? if i did something wrong could you tell me
local GamepassID = 703396350
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
game.Players.PlayerAdded:connect(function(Player)
Player.CharacterAdded:connect(function(Character)
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
repeat task.wait() until Character.Humanoid
Character.Humanoid.Died:connect(function()
Player:LoadCharacter()
end)
end
end)
end)
I dont know why I always see code backwards from how it’s presented to me but…
Why don’t you simply have the section of code that detects “player.HP = 0” do a “check for gamepass” and then simply “Respawn timer -60 seconds” or whatever it is prior to the death event.
it is still kinda the same . you should check if the player own the gamepass when they just join . it will improve performance but might require more scripting to check if the player buys the gamepass when playing the game
eg)
game.Players.PlayerAdded:Connect(function(plr)
if player own gamepass then
plr.CharacterAdded:Connect(function(char)
--do things
end)
end
end)
sorry if the script look weird. I dont have studio open rn
ok this is what i have now if i messed up could you correct me again? also i get what you’re saying now its better to check if they even have the gamepass before detecting if they die its better for performance
edit: i tested and it works
local GamepassID = 703396350
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(Player)
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.Died:connect(function()
Player:LoadCharacter()
end)
end)
end
end)
Pretty sure this script will work, it’s just that LoadCharacter is a yielding function which will wait for other scripts that are using the character.
you replaced the place id with a gamepass id of course it did that lol if you wanted to see what place the gamepass belongs to replace a gamepass id with the id im using