Seat gamepass (not working)

when the player sits, check if it has the gamepass, if it does: it does the animation, if not, it take damage. it’s not printing, so there’s definitely something wrong. Can anyone tell me?

my code:


local MarketplaceService = game:GetService("MarketplaceService")
local id = 1087508
seat = script.Parent

function added(child)
	if (child.className=="Weld") then
		local human = child.part1.Parent:FindFirstChild("Humanoid")
		if human ~= nil then
			local player = game.Players:GetPlayerFromCharacter(human)
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
				print("player has pass")
				anim = human:LoadAnimation(seat.sitanim)
				anim:Play()
			else
				print("Not allowed")
				human:TakeDamage(100)
			end
		end
	 end
end

function removed(child2)
	if anim ~= nil then
		anim:Stop()
		anim:Remove()
	end
end

seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)```

Can’t you use Seat.Occupant to determine if a player is sitting?

local MarketplaceService = game:GetService("MarketplaceService")
local id = 1087508
local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()	
	local human = seat.Occupant
	if human then
		local player = game.Players:GetPlayerFromCharacter(human.Parent)
		if not player then return end
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId,id) then
			print("player has pass")
			anim = human:LoadAnimation(seat.sitanim)
			anim:Play()
		else
			print("Not allowed")
			human:TakeDamage(100)
		end
	end
end)
1 Like