I’ve been trying to make a script for a player so that if they run a command and then try to sit down, they are blocked, however when they run it again with the “off” argument, they can sit as normal again.
However, I am clueless on this and keep getting stuck. This is my current script, and help would be appreciated.
Current Script
-- Function to enable seat bypass
local function enableSeatBypass(player)
local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
local seatConnection
seatConnection = humanoid.Seated:Connect(function(active, seat)
if seat and (seat:IsA("Seat") or seat:IsA("VehicleSeat")) then
seat.Disabled = true
task.wait(0.5)
seat.Disabled = false
end
end)
print("Seat bypass enabled for player:", player.Name)
return "Seat bypass enabled."
else
return "Unable to enable seat bypass. Player's character not found."
end
end
-- Function to disable seat bypass
local function disableSeatBypass(player)
local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
script:Disconnect()
print("Seat bypass disabled for player:", player.Name)
return "Seat bypass disabled."
else
return "Unable to disable seat bypass. Player's character not found."
end
end
-- Command handler
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local prefix = "!"
if string.sub(message, 1, #prefix) == prefix then
local args = {}
for word in string.gmatch(message, "%S+") do
table.insert(args, word)
end
local command = args[1]:lower()
table.remove(args, 1)
if command == "!sbp" then
if args[1] == "on" then
local result = enableSeatBypass(player)
elseif args[1] == "off" then
local result = disableSeatBypass(player)
else
end
end
end
end)
end)