Backpack Script Disabling

I have created a gamepass, that allows you to get a kick ability, which is usually disabled, that allows you to kick someone out of the game, if you kill them using the kick attack. The problem is, it keeps saying there is an infinite yield on LocalHamonKick, which is a local script stored in the Player’s backpack. Here is the script, and the explorer.

game.Players.PlayerAdded:Connect(function(plr)
	local bp = plr:WaitForChild("Backpack")
	local mps = game:GetService('MarketplaceService')
	if mps:UserOwnsGamePassAsync(plr.UserId, 23171784) then
		if plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true == false then
	print("active")
			bp:WaitForChild("LocalHamonKick").Disabled = false
			local ss = game.ServerScriptService
			ss.HamonKickServer.Disabled = false
		elseif  plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true  then
			print("deactive")
		bp:WaitForChild("LocalHamonKick").Disabled = false
			local ss = game.ServerScriptService
			ss.HamonKickServer.Disabled = false
			
		
		end
		
	end
end)

run this onCharacterAdded not onPlayerAdded

Okeh. Would this work? I’m developing this on a group game, so I don’t have the gamepass, and the person who usually does this testing is offline.

game.Players.CharacterAdded:Connect(function(plr)
local bp = plr:WaitForChild("Backpack")
local mps = game:GetService('MarketplaceService')

if mps:UserOwnsGamePassAsync(plr.UserId, 23171784) then
	if plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true == false then
		print("active")
		bp.LocalHamonKick.Disabled = false
		local ss = game.ServerScriptService
		ss.HamonKickServer.Disabled = false
	elseif  plr:WaitForChild("PlayerGui"):WaitForChild("KickGUI").Enabled == true  then
		print("deactive")
		bp.HamonKick.Disabled = false 
		local ss = game.ServerScriptService
		ss.HamonKickServer.Disabled = false


	end

	end
	end)

I was able to test, but in output it says, CharacterAdded is not a valid member of Players, “Players”

game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(character)
    -- do something here
  end)
end)

Oh, I’m dumb. tiky

This makes no sense why check if it is true and then false in one statement just do

if plr:WaitForChild("PlayerGui"):WaitForChild("KickGui").Enabled == false then 

Also do game:GetService("ServerScriptService")

I really feel like there is more issues here than waiting for the items in the backpack. Considering you are disabling a ServerScriptService script, based on the state of a single player.

Your script should in in a script, not local script, and if it detects the player owns the gamepass, then you should move the ‘tool’ the kick thing, into the player’s backpack from ServerStorage.

This helps prevent exploits.

Oh that was a typo I think. babbab

It is in a script, and okeh. I’ll try everythingi na bit.

local ServerStorage = game:GetService("ServerStorage")
local LocalHamonKick = ServerStorage:WaitForChild("LocalHamonKick")

function GiveKick(player)
	local Backpack = player:WaitForChild("Backpack")
	local MarketplaceService = game:GetService("MarketplaceService")
	
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId, 23171784) then
		LocalHamonKick:Clone().Parent = Backpack	
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		GiveKick(player)
	end)
end)

I’m on mobile right now, so it’s hard to type and I can’t access RS.

I would also use this

local success,err = pcall(function()
    MarketplaceService:UserOwnsGamePassAsync(player.UserId,gamepassId) -- or try adding a return at the beginning of this if it wont work
end)
 if success then
    --code here
else
    warn("Player Doesn't own Gamepass")
end

A failure on success, doesn’t mean they don’t own it, just there was a problem checking with the Roblox servers.

I know I just use Player Doesn't own Gamepass it is how I do prints doesn’t change the fact it works

function GiveKick(player)
	local Backpack = player:WaitForChild("Backpack")
	local MarketplaceService = game:GetService("MarketplaceService")
	
	local success,result = pcall(function()
		return MarketplaceService:UserOwnsGamePassAsync(player.UserId, 23171784)
	end)
	if success then
		if result == true then
			LocalHamonKick:Clone().Parent = Backpack
		else
			--doesnt own
		end
	else
		print(result) --result holds the error code
	end
end

Give me a second to test this all, since the person with the gamepass isn’t online right now, So I might respond a bit later.

you can always test without the gamepass owner, by replacing the gamepass id number with a gamepass id that you currently own.

Btw as I learned result is an false value so it is like the error I learned this from using DataStores by TheDevKing