I’m making a admin commands script in Roblox Studio. But whenever I execute a command using the script, I get the following error: “attempt to call a boolean value”. It doesn’t show the line or even the script in which the error happened. But the command still gets executed. When I place breakpoint and run the game, the game doesn’t break, and I still get the “attempt to call a boolean value” error. Something really weird is going on here, please help.
The code:
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local DataStoreService = game:GetService("DataStoreService")
local banDataStore = DataStoreService:GetDataStore("Bans")
local timebanDataStore = DataStoreService:GetDataStore("TimeBans")
local MessagingService = game:GetService("MessagingService")
MessagingService:SubscribeAsync("shutdownservers", function()
for i, player in pairs(Players:GetPlayers()) do
player:Kick("All servers where shutdown.")
end
end)
local serverBanned = {game.CreatorId}
function getPlayer(name)
for i, player in pairs(Players:GetPlayers()) do
if player.Name:lower() == name then
return player
end
end
for i, player in pairs(Players:GetPlayers()) do
if player.Name:lower():sub(1, #name) == name then
return player
end
end
end
function getPlayersFromWord(name, playerWhoSaid)
local playersList = Players:GetPlayers()
local playersToReturn = {}
name = name:lower()
if name == "all" then
playersToReturn = playersList
elseif name == "me" then
playersToReturn = {playerWhoSaid}
elseif name == "others" then
for i, player in pairs(playersList) do
if player ~= playerWhoSaid then
table.insert(playersToReturn, player)
end
end
elseif name == "friends" then
for i, player in pairs(playersList) do
if playerWhoSaid:IsFriendsWith(player.UserId) then
table.insert(playersToReturn, player)
end
end
elseif name == "premium" then
for i, player in pairs(playersList) do
if player.MembershipType == Enum.MembershipType.Premium then
table.insert(playersToReturn, player)
end
end
elseif name == "random" then
playersToReturn = {playersList[math.random(1, #playersList)]}
else
playersToReturn = {getPlayer(name)}
end
return playersToReturn
end
function getMessage(words)
local message = ""
for i, word in pairs(words) do
if i >= 3 then
message ..= word
if i < #words then
message ..= " "
end
end
end
if message == "" then
return nil
end
return message
end
local prefix = "!"
local ranks = {
[game.CreatorId] = 3
}
local commands = {
[1] = {
["speed"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
local speed = words[3]
for i, player in pairs(players) do
player.Character.Humanoid.WalkSpeed = speed
end
end;
["jumppower"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
local jumpPower = words[3]
for i, player in pairs(players) do
local humanoid = player.Character.Humanoid
humanoid.UseJumpPower = true
humanoid.JumpPower = jumpPower
end
end;
["size"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
local size = words[3]
for i, player in pairs(players) do
player.CameraMaxZoomDistance = 128*size/0.5
local humanoid = player.Character.Humanoid
humanoid.BodyDepthScale.Value = size
humanoid.BodyHeightScale.Value = size
humanoid.BodyWidthScale.Value = size
humanoid.HeadScale.Value = size
end
end;
["jump"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
local jumps = words[3] or 1
for i, player in pairs(players) do
spawn(function()
for i = 1, jumps do
local humanoid = player.Character.Humanoid
humanoid.Jump = true
wait(1)
end
end)
end
end;
["chat"] = function(words, playerWhoChatted)
local message = getMessage(words)
if not message then
return
end
local players = getPlayersFromWord(words[2], playerWhoChatted)
for i, player in pairs(players) do
Chat:Chat(player.Character, Chat:FilterStringForBroadcast(message, player))
end
end;
["explode"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
for i, player in pairs(players) do
local hrp = player.Character.HumanoidRootPart
hrp.Parent:BreakJoints()
local explosion = Instance.new("Explosion")
explosion.Position = hrp.Position
explosion.BlastPressure = 500000
explosion.BlastRadius = 10
explosion.Parent = hrp
end
end;
["forcefield"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
for i, player in pairs(players) do
local char = player.Character
spawn(function()
local field = Instance.new("ForceField", char)
wait(10)
field:Destroy()
end)
end
end;
["spin"] = function(words, playerWhoChatted)
Instance.new("BodyAngularVelocity")
end
};
[2] = {
["kick"] = function(words, playerWhoChatted)
local message = getMessage(words)
local players = getPlayersFromWord(words[2], playerWhoChatted)
for i, player in pairs(players) do
player:Kick(message or "You where kicked by "..playerWhoChatted.Name)
end
end;
["serverban"] = function(words, playerWhoChatted)
local message = words[3]
local players = getPlayersFromWord(words[2], playerWhoChatted)
for i, player in pairs(players) do
table.insert(serverBanned, player.UserId)
player:Kick("You where banned from this server.")
end
end;
["kill"] = function(words, playerWhoChatted)
local players = getPlayersFromWord(words[2], playerWhoChatted)
for i, player in pairs(players) do
local humanoid = player.Character.Humanoid
humanoid.BreakJointsOnDeath = false
humanoid.Health = 0
end
end
};
[3] = {
["ban"] = function(words)
local player = getPlayer(words[2])
if player then
banDataStore:SetAsync(player.UserId, true)
player:Kick("You where banned from this game.")
end
end;
["shutdownservers"] = function()
MessagingService:SubscribeAsync("shutdownservers")
end
}
}
Players.PlayerAdded:Connect(function(player)
if table.find(serverBanned, player.UserId) then
player:Kick("You where previously banned from this server.")
end
while true do
local succes = pcall(function()
if banDataStore:GetAsync(player.UserId) then
player:Kick("You have been previously banned.")
end
end)
if succes then
break
end
end
local playerRank = ranks[player.UserId]
if playerRank then
player.Chatted:Connect(function(message)
local words = message:split(" ")
if words[1]:sub(1, 1) == prefix then
local command = words[1]:sub(2):lower()
for i = 1, playerRank do
local Function = commands[i][command]
if Function then
Function(words, player)
break
end
end
end
end)
end
end)