I am making a remote script where the player joins it will detect if the player has a badge or a gamepass. Everything else in the remote script works fine its just I need it to disable a script if the player does NOT have the badge or gamepass. I tried looking for hours but nobody responded. Here is the script:
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeid = script.Parent.Parent:WaitForChild("BadgeID")
local gamepassid = script.Parent.Parent:WaitForChild("GamepassID")
local MarketplaceService = game:GetService("MarketplaceService")
local function playerGates(player)
local Character = player.Character
local HasBadge, Result = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
local HasGamepass, Result2 = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)
if HasBadge == false then
game.Workspace.Gate2.TouchGateScript.Enabled = false
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local MarketplaceService = game:GetService("MarketplaceService")
local badgeid = script.Parent.Parent:WaitForChild("BadgeID").Value
local gamepassid = script.Parent.Parent:WaitForChild("GamepassID").Value
local function playerGates(player)
local Character = player.Character
local HasBadge, Result = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
local HasGamepass, Result2 = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)
if not HasBadge or not HasGamepass then
local gateScript = game.Workspace:FindFirstChild("Gate2") and game.Workspace.Gate2:FindFirstChild("TouchGateScript")
if gateScript then
gateScript.Enabled = false
end
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)
Huh if this doesnt work then to be honest I have no idea what to do.
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local MarketplaceService = game:GetService("MarketplaceService")
local badgeid = script.Parent.Parent:WaitForChild("BadgeID").Value
local gamepassid = script.Parent.Parent:WaitForChild("GamepassID").Value
local function playerGates(player)
local Character = player.Character
local HasBadge, BadgeResult = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
local HasGamepass, GamepassResult = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)
if not HasBadge or not HasGamepass then
local gateScript = game.Workspace:FindFirstChild("Gate2") and game.Workspace.Gate2:FindFirstChild("TouchGateScript")
if gateScript then
gateScript.Enabled = false
end
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)
Here is the script so far, I changed the gamepassid and badgeid so you can see it. But still does not work.
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local MarketplaceService = game:GetService("MarketplaceService")
local badgeid = 0
local gamepassid = 0
local function playerGates(player)
local Character = player.Character
local HasBadge, BadgeResult = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
local HasGamepass, GamepassResult = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)
if not HasBadge or not HasGamepass then
local gateScript = game.Workspace:FindFirstChild("Gate2") and game.Workspace.Gate2:FindFirstChild("TouchGateScript")
if gateScript then
gateScript.Enabled = false
end
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)
Yeah it still does not work. I used 2 accounts at the same time, 1 that does not have gamepass and badge and 1 that has both of it. They both have enabled scripts just like before when I switched the gamepassID and BadgeID to 0
1 Worked. The badgeID works alone but not the gamepassID
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local MarketplaceService = game:GetService("MarketplaceService")
local badgeid = 155440073325875
local gamepassid = 1014470325
local function playerGates(player)
local Character = player.Character
local Success, HasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeid)
end)
local Success2, HasGamepass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)
if not HasBadge or not HasGamepass then
local gateScript = game.Workspace:FindFirstChild("Gate2") and game.Workspace.Gate2:FindFirstChild("TouchGateScript")
if gateScript then
gateScript.Enabled = false
end
end
end
local event = game.ReplicatedStorage.JoinEvent
event.OnServerEvent:Connect(function(player)
playerGates(player)
end)