Hello. I was adding gamepass/badge restrictions to a vehicle spawner.
I tried to test it, but it doesn’t detect if player owns badge/pass.
Script:
local config = script.Parent
local pass = config.IsGamePass.ID.Value
local badge = config.IsBadge.ID.Value
local button = script.Parent.Parent:FindFirstChild("Button")
local ms = game:GetService("MarketplaceService")
local badges = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(add)
local plr = game.Players:GetPlayerFromCharacter(add)
if config.IsGamePass.Value == true and ms:UserOwnsGamePassAsync(plr.UserId, pass) then
button.Changed:Connect(function()
if button.Color == Color3.new(0.0352941, 0.537255, 0.811765) then
button.Color = Color3.new(0.784314, 0, 1)
end
end)
elseif config.IsBadge.Value == true and badges:UserHasBadgeAsync(plr.UserId, badge) then
button.Changed:Connect(function()
if button.Color == Color3.new(0.0352941, 0.537255, 0.811765) then
button.Color = Color3.new(1, 0.615686, 0)
end
end)
else
for _, scripts in pairs(script.Parent.Parent:GetDescendants()) do
if scripts:IsA("Script") and scripts.RunContext == "Legacy" then
script.Parent.Parent.Button.Color = Color3.new(0.196078, 0.196078, 0.196078)
script.Parent.Parent.Button.VehicleLocked.Transparency = 0
scripts.Enabled = false
end
end
end
end)
Explorer: (the localscript is actually a serverscript with runcontext set to client)