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