In my survival game, when the player dies they lose all there items in their inventory. However, I have made a gamepass where they keep the items, but I don’t know how to make the script for the inventory loss false.
game.GetService(“Marketplaceservice”)
local MarketPlaceService = true
game.Players.Localplayer.gamepass
if LocalPlayer.hasgamepass then
game.Players UserOwnsGamepassAsync
local GAMEPASSID = 0 — the gamepass’ id
if player.UserOwnsGamepassAsync = false do
game.playerscripts.Inventoryloss = true
if player.UserOwnsGamepassAsync = true do
game.playerscripts.Inventoryloss = false
end
Now, this is pretty hard considering the fact that a script needs to be false/true by owning a gamepass. This is tricky in many ways by the main loss script being false.
I don’t know how to do this, but its pretty hard and annoying on how much times i re-wrote it and it doesnt work.
-- LocalScript
local MPS = game:GetService("MarketplaceService")
local PassID = 1 -- Your gamepass ID
local plrservice = game:GetService("Players")
local function onPlayerAdded(plr)
local hasPass = false
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, PassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
-- Make them keep items
end
if hasPass == false then
-- Remove their items
end
plrservice.ChildAdded:Connect(onPlayerAdded)
I noticed your problem. I will provide you a script that you can use for your game.
Let me know for any problems/errors. As I noticed some of your errors I will explain every action. This script must be in a SERVERSCRIPT. The InventoryLoss script can still be a localscript.
local gamepassid = "000000" -- insert your gamepass id here
We are declearing with local the gamepass id which will be used later on for checking if the players owns it.
local marketplace = game:GetService("MarketplaceService")
Here we are requesting the market place service with the :GetService() function.
local inventoryscript = game.Workspace.InventoryLoss -- make sure to insert a valid script with a valid location. (it cannot be PlayerStarterScripts. It must be ServerStorage, ReplicatedStorage, ReplicatedFirst.)
Now we are getting the inventory script which will be disabled if the player owns the gamepass.
Now I will provide under here the whole script for you to copy it.
local gamepassid = "00000" -- insert your gampass id here
local marketplace = game:GetService("MarketplaceService")
local losingscript = game.Workspace.InventoryLosinScript
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
local owns,err = pcall(function()
itemowned = marketplace:UserOwnsGamepassAsync(plr.UserId, gampeassid)
end
if itemowned == true then
losingscript.Disabled = false
else
losingscript.Disabled = true
end
end)
Hope this helped. Let me know if you have some error or trouble with this.