How to detect a seat

Hello I want to know in what seat a player is sitting, and I’m using

Button.MouseButton1Click:Connect(function()
	if player.Character:FindFirstChild("Humanoid").SeatPart ~= "DriveSeat" then
		
		local Camera1 = workspace.HousesSpawn.Plot1:WaitForChild("Camera1", 1)
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = Camera1.CFrame
		
		for i,v in ipairs(player.PlayerGui:GetDescendants()) do
			if v:IsA("ScreenGui") and v.Name ~= "CamerasGUI" then
				v.Enabled = false 
			end
		end

		Event:FireServer()

		TextLabel.Text = "Camera1"
		Frame.Visible = true
		BarCall.Visible = false
		UpperButtons.Visible = false
		--DoorCall.Visible = false
		--HouseCall.Visible = false
		--Button.Visible = false
		--controls:Disable()
	end
end)

But it didn’t work…

Use the Humanoid.SeatPart property

I’m using it but it didn’t work…


Button.MouseButton1Click:Connect(function()
	if player.Character:FindFirstChild("Humanoid").SeatPart ~= "DriveSeat" then
		
		local Camera1 = workspace.HousesSpawn.Plot1:WaitForChild("Camera1", 1)
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = Camera1.CFrame
		
		for i,v in ipairs(player.PlayerGui:GetDescendants()) do
			if v:IsA("ScreenGui") and v.Name ~= "CamerasGUI" then
				v.Enabled = false 
			end
		end

		Event:FireServer()

		TextLabel.Text = "Camera1"
		Frame.Visible = true
		BarCall.Visible = false
		UpperButtons.Visible = false
		--DoorCall.Visible = false
		--HouseCall.Visible = false
		--Button.Visible = false
		--controls:Disable()
	end
end)

Your checking if its not the driver seat, is that intentional?

yeah I want that if a player is sitting in the DriveSeat (VehicleSeat), the script doesn’t make the Gui called "CarButtons " visible

try adding a print statement under the the first check. Tell me if it prints or not

yeah it prints… both (hello1 and hello2) but I don’t understand why

local Button = script.Parent
local Frame = script.Parent.Parent.Parent.Frame.CamerasGUI.CamerasMenu

local CloseButton = Frame.CloseButton

local TextLabel = script.Parent.Parent.Parent.Frame.CamerasGUI.CamerasMenu.ImageLabel.CameraName

local player = game:GetService("Players").LocalPlayer

--local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

local BarCall = script.Parent.Parent.Parent.BarCall
local UpperButtons = script.Parent.Parent


local cam = workspace.CurrentCamera
local Event = script.Parent:WaitForChild("Event", 1)


Button.MouseButton1Click:Connect(function()
	print("Hello1")
	if player.Character:FindFirstChild("Humanoid").SeatPart ~= "DriveSeat" then
		print("hello2")
		local Camera1 = workspace.HousesSpawn.Plot1:WaitForChild("Camera1", 1)
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = Camera1.CFrame
		
		for i,v in ipairs(player.PlayerGui:GetDescendants()) do
			if v:IsA("ScreenGui") and v.Name ~= "CamerasGUI" then
				v.Enabled = false 
			end
		end

		Event:FireServer()

		TextLabel.Text = "Camera1"
		Frame.Visible = true
		BarCall.Visible = false
		UpperButtons.Visible = false
		--DoorCall.Visible = false
		--HouseCall.Visible = false
		--Button.Visible = false
		--controls:Disable()
	end
end)

Dose “Hello, 2” print? if so the problem is under the check

The seatPart is an Object, not a string, if you want to check its name, use SeatPart.Name

Button.MouseButton1Click:Connect(function()
	if player.Character:FindFirstChild("Humanoid").SeatPart.Name ~= "DriveSeat" then
		
		local Camera1 = workspace.HousesSpawn.Plot1:WaitForChild("Camera1", 1)
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = Camera1.CFrame
		
		for i,v in ipairs(player.PlayerGui:GetDescendants()) do
			if v:IsA("ScreenGui") and v.Name ~= "CamerasGUI" then
				v.Enabled = false 
			end
		end

		Event:FireServer()

		TextLabel.Text = "Camera1"
		Frame.Visible = true
		BarCall.Visible = false
		UpperButtons.Visible = false
		--DoorCall.Visible = false
		--HouseCall.Visible = false
		--Button.Visible = false
		--controls:Disable()
	end
end)
1 Like

yes it prints Hello 2 , every time

Dose the event fire to the server?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.