How can I make a script false when you own a gamepass?

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.

3 Likes

Many errors…

-- 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)
3 Likes

But theres a script for the losing the inventory. its called InventoryLosingScript

Can you show us the code, so we can help you.

1 Like

If you want them to keep certain tools after they respawn, you have to either:

  1. Clone & parent their tools when the character has spawned
  2. Put the tools in StarterGear. More information: StarterGear | Roblox Creator Documentation.

The second option would be more effective as you don’t need to give them their tools everytime they respawn.

1 Like

Show us the code. We can either combine it or use globals to access it

1 Like

The code is shown in the post.

1 Like

Is the code from the script called InventoryLosingScript?

1 Like

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. :yum:

2 Likes

The code from AdmiralSloppy should work.

2 Likes

For feature reference, please ask in #forum-feedback:forum-help instead of a scripting support thread.

https://devforum.roblox.com/t/how-do-i-get-a-title-role-or-tag-next-to-my-name-programmer-builder-artist-etc/910601

1 Like