Hello Developers! I am having this issue with my lua script called “Activate” so when the player presses or hits the button, it spawns the car. I recently made it so that players with the gamepass can only touch it, but now I am trying to make a subscription and gamepass only touch it. I am new with the subscription and how to make the script read if the player has the subscription, so I don’t know how to work it just yet. Here is the script if someone can help me with what I am doing wrong, it just comes up with the output: Error while checking if player has subscription: Unable to cast value to Object. Here is the script:
local button = script.Parent
local regen = button.Parent.Regen
local gamePassId = 842684539
local subscriptionID = "EXP-4001571221994733782"
local debounce = false
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local function hasSubscription(player)
local subStatus = {}
local success, message = pcall(function()
subStatus = MarketplaceService:GetUserSubscriptionStatusAsync(player.UserId, subscriptionID)
end)
if not success then
return false
end
end
function onTouch(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
print("Player detected: " .. player.Name)
local hasGamePass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId)
local hasSub = hasSubscription(player)
print("GamePass: " .. tostring(hasGamePass) .. ", Subscription: " .. tostring(hasSub))
if (hasGamePass or hasSub) and debounce == false then
debounce = true
button.BrickColor = BrickColor.Black()
regen.Value = 1
wait(1)
regen.Value = 0
wait(100)
button.BrickColor = BrickColor.White()
debounce = false
end
else
end
end
button.Touched:Connect(onTouch)
Thank you! Have a great day.