Remote Script wont detect if player has badge or gamepass

The gamepass still does not work.
Screenshot 2024-12-27 201451
The 30 is the timer to teleport the players into the server and it does not go down when I have the gamepass when it should be

1 Like

Thatā€™s odd, my reproduction of the code seems to be working fine. When I donā€™t own either, it prints in the stop statement. When I own one, it does not. Same as owning both. Have you tried checking your countdown script?

Do you think it is the event script itself?

local Players = game:GetService("Players")
local event = game.ReplicatedStorage.JoinEvent

Players.LocalPlayer.CharacterAdded:Connect(function(character)
	event:FireServer()
end)

This script is in StarterPlayerScripts

Wait are the gamepassid & badgeids stored under a numbervalue?

If so: you arenā€™t getting the value of them. You just got the values themself. Youā€™ll want to add .Value to the variables defining the badgeid & gamepassid.

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeid = script.Parent.Parent:WaitForChild("BadgeID").Value
local gamepassid = script.Parent.Parent:WaitForChild("GamepassID").Value
local MarketplaceService = game:GetService("MarketplaceService")

local function playerGates(player)
	local Character = player.Character
	--I swapped "Result" with "HasBadge"
	local Success, HasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
	end)
	--I swapped "Result2" with "HasGamepass"
	local Success2, HasGamepass = pcall(function()
		return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
	end)

	if not ((Success and HasBadge) or (Success2 and HasGamepass)) then
		game.Workspace.Gate2.TouchGateScript.Enabled = false
	end
end

local event = game.ReplicatedStorage.JoinEvent

event.OnServerEvent:Connect(function(player)
	playerGates(player)
end)

Oh I wasnt using a number value I just did the idā€™s in the script and number value actually worked for the gamepassID

Nvm it didnt work when the player does not have the gamepass or badge

I added the .Value to the end of it and it does not disable it when the player does not have a badge or gamepass

To debug the code you can type this into the command bar and press enter. Just make sure to fill out ā€œBadge_Id_Hereā€, ā€œGamepass_Id_Hereā€ and ā€œPlayer_Id_Hereā€. Itā€™ll print in the output each check.

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeid = Badge_Id_Here
local gamepassid = Gamepass_Id_Here
local MarketplaceService = game:GetService("MarketplaceService")

local function playerGates(player)
	--local Character = player.Character
	--I swapped "Result" with "HasBadge"
	local Success, HasBadge = pcall(function()
		local Result = BadgeService:UserHasBadgeAsync(player, badgeid)
		print("Has badge:", Result)
		return Result
	end)
	--I swapped "Result2" with "HasGamepass"
	local Success2, HasGamepass = pcall(function()
		local Result = MarketplaceService:UserOwnsGamePassAsync(player, gamepassid)
		print("Has gamepass:", Result)
		return Result
	end)

	if not ((Success and HasBadge) or (Success2 and HasGamepass)) then
		print("Has no gamepass or badge.")
		--game.Workspace.Gate2.TouchGateScript.Enabled = false
	else
		print("Success, has badge or gamepass")
	end
end

print(Player_Id_Here)

Yeah I did that before and the gamepassID did not work. I tested the script and now it still does not disable the script when the player does not have badge or the gamepass

Seems to be working fine for me
image
image
image

Screenshot 2024-12-27 203751

Have you tried running the debug function in studioā€™s command bar? It should print what it could find, and what it could not. Then with that, should print if it should disable the script.

Ah wait, this might just be a replication issue.

local Players = game:GetService("Players")
local event = game.ReplicatedStorage:WaitForChild("JoinEvent")

Players.LocalPlayer.CharacterAdded:Connect(function(character)
	event:FireServer()
end)

Still nothing (35 characters characters)

Could I give you the game uncopylocked?

That would work. I was busy recreating the setup to the best of my abilities using the code you sent to test it out.

The Infinite Backrooms - Roblox Uncopylocked

Alright Iā€™ve fixed the gate, your issue is that when the player doesnā€™t have access to chapter 2, it completely disables the gate entirely. Iā€™ve disabled the script that does that and instead modified the gate2 touch script to just check if they have access to the chapter. If not, just do nothing.
Backrooms thingy fixed.rbxl (100.8 KB)

1 Like

It works thanks for putting all this time into this script!

1 Like