Problems with a seat lock (SCRIPTING)

Hey!

I’m working on a seat lock for my bus, so if on the GUI I would have it turn on, no one could jump. I’ve tried countless solutions to make it work, but it isn’t working.

There are no errors, but this segment of the script isn’t working:

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	task.wait(0.033)
	if seat.Occupant then
		print("1")
		if Active == false then
			print("2")
				print("3")
				Active = true
				Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
				print("4")
				if Player ~= nil then
					local PlayerGui = Player:FindFirstChild("PlayerGui")
					if PlayerGui ~= nil then
						NewGui = GUI:Clone()
						NewGui.Parent = PlayerGui
						print("działa")
						onSit()
					end
				end
		end
	end
	
end)

This is the whole script:

task.wait(3)
Players = game:GetService("Players")

seat = script.Parent
GUI = script.NonJumpNotifications
Active = false
Player = nil
NewGui = nil
local value = nil
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local service = game:GetService("Players")
local db=true

local function onSit()
	if db then db=false task.wait(0.033)
	local seat2 = script.Parent.Parent.Parent.Parent.Parent.DriveSeat
	local part = workspace.Part

	print("działa do tej pory")
	if seat2:GetPropertyChangedSignal("Occupant") then
		if seat2.Occupant then
			local occupant = seat.Occupant
			local char = occupant.Parent
			local username = char.Name
			local user = ""..username

			local usergui = service.user.PlayerGui

			if usergui:FindFirstChild("A-Chassis Interface").AntiJump.Value == true then
				local seatWeld = seat.SeatWeld
				local humanoid = seatWeld.Part1.Parent.Humanoid
				NewGui.On.Enabled = true
				NewGui.Off.Enabled = false
				humanoid.JumpHeight = 0
				controls:Disable()
			end	
			if usergui:FindFirstChild("A-Chassis Interface").AntiJump.Value == false then
				local seatWeld = seat.SeatWeld
				local humanoid = seatWeld.Part1.Parent.Humanoid
				NewGui.On.Enabled = true
				NewGui.Off.Enabled = false
				humanoid.JumpHeight = 7.2
				controls:Enable()
			end
		end
		print("no one")
	end
	db = true
end
end



local function onChange()
	task.wait(0.033)
	if seat.Occupant ~= nil then
		local seat2 = script.Parent.Parent.Parent.Parent.Parent.DriveSeat
		local part = workspace.Part

		print("działa do tej pory")
		if seat2:GetPropertyChangedSignal("Occupant") then

			local occupant = seat.Occupant
			local char = occupant.Parent
			local username = char.Name
			local user = service:GetPlayerFromCharacter(char)

			local usergui = user.PlayerGui

			if usergui:FindFirstChild("A-Chassis Interface").AntiJump.Value == true then
				local seatWeld = seat.SeatWeld
				local humanoid = seatWeld.Part1.Parent.Humanoid
				NewGui.Off.Enabled = true
				NewGui.On.Enabled = false
				humanoid.JumpHeight = 0
				controls:Disable()
			elseif usergui:FindFirstChild("A-Chassis Interface").AntiJump.Value == false then
				local seatWeld = seat.SeatWeld
				local humanoid = seatWeld.Part1.Parent.Humanoid
				NewGui.On.Enabled = true
				NewGui.Off.Enabled = false
				humanoid.JumpHeight = 7.2	
				controls:Enable()
			end
		end

	end
end


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	task.wait(0.033)
	if seat.Occupant then
		print("1")
		if Active == false then
			print("2")
				print("3")
				Active = true
				Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
				print("4")
				if Player ~= nil then
					local PlayerGui = Player:FindFirstChild("PlayerGui")
					if PlayerGui ~= nil then
						NewGui = GUI:Clone()
						NewGui.Parent = PlayerGui
						print("działa")
						onSit()
					end
				end
		end
	end
	
end)

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	task.wait(0.033)
	if not seat.Occupant then
		if Active == true then
			Active = false
			pcall(function() NewGui:Destroy() end)
			Player = nil
			NewGui = nil
		end
	end

end)


for i, v in pairs() do
	local seat2 = script.Parent.Parent.Parent.Parent.Parent.DriveSeat
	local part = workspace.Part

	if seat2:GetPropertyChangedSignal("Occupant") then
		local occupant = seat.Occupant
		local char = occupant.Parent
		local username = char.Name
		local user = service:GetPlayerFromCharacter(char)

		local usergui = user.PlayerGui
		usergui:FindFirstChild("A-Chassis Interface").AntiJump.Changed:Connect(function()
			onChange()
		end)

	end	
end


I would be so grateful, if someone could help me with this problem.

Kind regards,
official

1 Like

ServerScript… (not your script… an example)

task.wait(3)
local seat=script.Parent
local players=game:GetService("Players")
local player=nil
local db=true

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if(db)then db=false task.wait(0.033) --need a pause

		if not(seat.Occupant)then print("exiting")
		elseif(seat.Occupant)then print("sitting")

			player=players:GetPlayerFromCharacter(seat.Occupant.Parent)

			print(player)
		end db=true
	end
end)

Updated to be closer towards yours.

It doesn’t work, still. There is no bigger problem with the script, just with this:

seat.Changed:connect(function()
	if seat.Occupant then
		print("1")
		if Active == false then
			print("2")
				print("3")
				Active = true
				Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
				print("4")
				if Player ~= nil then
					local PlayerGui = Player:FindFirstChild("PlayerGui")
					if PlayerGui ~= nil then
						NewGui = GUI:Clone()
						NewGui.Parent = PlayerGui
						print("działa")
						onSit()
					end
				end
		end
	end
	
end)

It isn’t printing nothing when I sit.

That isn’t how you call that … and it needs to be a server script.
Just tested mine before posting too.

It should look like how I’ve posted it above.
(the way I’ve been doing it, anyways)

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if(db)then db=false task.wait(0.033) --need a pause

It is a server script + how should it look like?

Hi,
it should look like this

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
 local occupant = seat.Occupant

 if occupant and not Active then
  Active = true
  Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)

  if Player then
   local PlayerGui = Player:FindFirstChild("PlayerGui")

   if PlayerGui then
    NewGui = GUI:Clone()
    NewGui.Parent = PlayerGui
    onSit()
    newGui = nil
    print("pewnie nie dziala xD")
   end

  end

 end

end)