Kicking out a player from a seat if they're not a premium member

hello
I’m trying to make a gamepass/premium car and only allow them to drive the car, and if a player that’s not a premium and or has not brought the gamepass the Seat would kick the player out of the seat
I’ve already coded in if the player is in a seat then it’ll activate the if statements, but my problem is, it’s giving me errors about " attempt to index nil with ‘MembershipType’ " it used to give me errors about the player before now it doesn’t because I was editing it trying to fix it then stopped, and now I’m asking for help. I was trying to get the player who’s sitting on the seat and trying to check if they’re premium or not but I’ve failed.
I’ve asked for help on multiple discord servers they tried to help me but it was still giving me error’s and I’ve looked it up in google and I couldn’t really find much about the premium. I’m trying to figure out the premium part first before I start working on the gamepass.

	Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
		if Seat.Occupant ~= nil then
			countertext.TextLabelS.Visible = false ---ingore this
			countertext.TextLabelIU.Visible = true
			countertext.TextLabel.Visible = false
		else
			Spawner.Value = 1 ---ingore this
		end
			player = game.Players:GetPlayerFromCharacter(script.Parent)

		if player.MembershipType == Enum.MembershipType.Premium then
			print(player.Name..' has premium!')
		else
			Seat.Disabled = true
			wait(0.1)
			Seat.Disabled = false 
		end
	end)
end

Seat.Changed:Connect(onChanged)

Where is this script located in relation to everything? You may not actually be getting a player from script.Parent

Try using
player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
since it seems Occupant gets set to the Player’s humanoid. Let me know if that helps.

Also, I think I’ve heard the best way to make a player stop sitting is to destroy the weld that is created when the player sits.

1 Like

this script is located in the VehicleSeat
it’s still giving me error’s
Workspace.Spawner.Station.Jeff Bezo’s car.VehicleSeat.Script:8: attempt to index nil with ‘Parent’

(Normal script inside of the seat)

script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	local Occupant = script.Parent.Occupant
	if Occupant == nil then return end
	local Player = game.Players:GetPlayerFromCharacter(Occupant.Parent)
	if Player then
		if not (Player.MembershipType == Enum.MembershipType.Premium) then
			wait(0.25)
			script.Parent.Disabled = true
			wait(1)
			script.Parent.Disabled = false
		end
	end
end)
2 Likes