I’m trying to create a script that stops players from sitting when they run a command, sadly, only the disable part of the script works, and it disables all seats in the game, but when I try to enable them, they dont enable. Here are the two scripts and I’d really appreciate it if you could give me some tips and educate me!
Adonis Admin Command;
local event = game:GetService("ReplicatedStorage").PreventSitEvent
return function(Vargs)
local server, service = Vargs.Server, Vargs.Service
server.Commands.NoSitCommand = {
Prefix = server.Settings.Prefix; -- Prefix to use for command
Commands = {"preventSeat"}; -- Commands
Args = {"true", "false"}; -- Command arguments
Description = " "; -- Command Description
Hidden = false; -- Is it hidden from the command list?
Fun = false; -- Is it fun?
AdminLevel = "Moderators"; -- Admin level; If using settings.CustomRanks set this to the custom rank name (eg. "Baristas")
Function = function(plr, args) -- Function to run for command
if args[1] == "true" then
event:FireClient(plr, true)
elseif args[2] == "false" then
event:FireClient(plr, false)
end
end
}
end
and this is the StarterPlayerScript;
-- StarterPlayer > StarterPlayerScripts > SitControlScript
local event = game.ReplicatedStorage.PreventSitEvent
local player = game.Players.LocalPlayer
function disableSeats(parent)
for _, child in pairs(parent:GetChildren()) do
if child:IsA("Seat") then
child.Disabled = true
print(child.Name)
end
disableSeats(child) -- Recursively disable seats in children
end
end
function enableSeats(parent)
for _, child in pairs(parent:GetChildren()) do
if child:IsA("Seat") and child.Disabled == true then
child.Disabled = false
print(child.Name)
end
enableSeats(child) -- Recursively enable seats in children
end
end
if player then
local success, err = pcall(function()
event.OnClientEvent:Connect(function(torf)
if torf then
disableSeats(workspace)
else
enableSeats(workspace)
end
end)
end)
if not success then
warn("Error in SitControlScript:", err)
end
else
warn("LocalPlayer not found.")
end
Thank you alot in advance!