I made an admin command that spawns blocks in a position and it doesn’t work I tried using the assistant and it added more prints/warns to debug it and I got this:
10:12:05.243 [AdminCmd] Admin Account2eoekowkwlw typed something starting with '/spawnblocks' but it didn't match the full command pattern: '/spawnblocks 100' - Server - Script:147
Here is the code for it:
local spawnerPart = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local blockATemplate = replicatedStorage:WaitForChild("BlockA")
local workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local alreadyTriggered = false
-- Admin configuration
local adminUsernames = {
"Account2eoekowkwlw", -- IMPORTANT: Replace with actual admin usernames, CASE-SENSITIVE
"JaydenHasstinkyToes" -- Add more admin usernames as needed
}
local ADMIN_COMMAND = "/spawnblocks"
-- Define spawn coordinates
local SPAWN_MIN_X = 200
local SPAWN_MAX_X = -300
local SPAWN_Y = 550
local SPAWN_Z = -400
-- Function to spawn BlockA instances
local function spawnBlockAInstances(count)
if not blockATemplate then
warn("BlockA template not found in ReplicatedStorage.")
return
end
for i = 1, count do
local newBlock = blockATemplate:Clone()
newBlock.Parent = workspace
local randomX = SPAWN_MIN_X + math.random() * (SPAWN_MAX_X - SPAWN_MIN_X)
newBlock.CFrame = CFrame.new(randomX, SPAWN_Y, SPAWN_Z)
newBlock.Anchored = false
end
print(count .. " BlockA instances spawned via function call for command.")
end
-- Touched event handler
spawnerPart.Touched:Connect(function(hit)
if alreadyTriggered or not blockATemplate then
return
end
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
if not player then
if hit.Parent and hit.Parent.Parent then
character = hit.Parent.Parent
player = Players:GetPlayerFromCharacter(character)
end
if not player then
return
end
end
alreadyTriggered = true
spawnBlockAInstances(50) -- Spawn 50 blocks on touch
spawnerPart.Transparency = 1
spawnerPart.CanCollide = false
local lowPolyIslandFolder = workspace:FindFirstChild("Low Poly Island")
if lowPolyIslandFolder then
for _, descendant in lowPolyIslandFolder:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Transparency = 1
descendant.CanCollide = false
end
end
else
warn("Low Poly Island folder not found in Workspace when making transparent.")
end
task.wait(15)
spawnerPart.Transparency = 0
spawnerPart.CanCollide = true
if lowPolyIslandFolder then
for _, descendant in lowPolyIslandFolder:GetDescendants() do
if descendant:IsA("BasePart") then
descendant.Transparency = 0
descendant.CanCollide = true
end
end
else
warn("Low Poly Island folder not found in Workspace when reverting transparency.")
end
alreadyTriggered = false
end)
-- Admin command handler function
local function handlePlayerChat(player, message)
print("[AdminCmd] handlePlayerChat called for player: " .. player.Name .. ", message: '" .. message .. "'")
local lowerMessage = string.lower(message)
local isPlayerAdmin = false
for _, adminName in adminUsernames do
if player.Name == adminName then -- Player names ARE case-sensitive
isPlayerAdmin = true
break
end
end
if not isPlayerAdmin then
-- Check if the message starts with the admin command to provide feedback even if not admin
if string.sub(lowerMessage, 1, string.len(ADMIN_COMMAND)) == string.lower(ADMIN_COMMAND) then
print("[AdminCmd] Player " .. player.Name .. " attempted admin command '" .. message .. "' but is NOT an admin. Check adminUsernames list (case-sensitive).")
end
return -- Exit if not an admin
end
-- If execution reaches here, player is an admin.
print("[AdminCmd] Player " .. player.Name .. " IS an admin.")
-- Define the pattern to match the command and an optional count
local pattern = "^(" .. string.lower(ADMIN_COMMAND) .. ")(%s+(%d+))?%s*$" -- Corrected: Removed ?: and adjusted capture group
local cmd, _, countStr = string.match(lowerMessage, pattern) -- Corrected: Added _ for the intermediate capture
if cmd then
local countToSpawn = 50 -- Default number of blocks
if countStr then
local num = tonumber(countStr)
if num and num > 0 then
countToSpawn = num
print("[AdminCmd] Admin command '" .. cmd .. " " .. countToSpawn .. "' received from " .. player.Name)
else
print("[AdminCmd] Admin command '" .. cmd .. "' received from " .. player.Name .. " with invalid count '" .. countStr .. "'. Defaulting to " .. countToSpawn .. " blocks.")
end
else
print("[AdminCmd] Admin command '" .. cmd .. "' received from " .. player.Name .. ". No count specified. Defaulting to " .. countToSpawn .. " blocks.")
end
spawnBlockAInstances(countToSpawn)
else
-- This means the player is an admin, but the typed message didn't match the ADMIN_COMMAND pattern.
-- This can happen if they type something else, like "/help" if ADMIN_COMMAND is "/spawnblocks".
-- Only print if the message started with the command prefix but didn't fully match (e.g. typo in command)
if string.sub(lowerMessage, 1, string.len(ADMIN_COMMAND)) == string.lower(ADMIN_COMMAND) then
print("[AdminCmd] Admin " .. player.Name .. " typed something starting with '".. ADMIN_COMMAND .."' but it didn't match the full command pattern: '" .. message .. "'")
end
end
end
-- Function to set up chat listener for a player
local function onPlayerAdded(player)
player.Chatted:Connect(function(message)
handlePlayerChat(player, message)
end)
end
-- Connect chat listener for players already in the game
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
-- Connect chat listener for players who join later
Players.PlayerAdded:Connect(onPlayerAdded)
line 147:
if string.sub(lowerMessage, 1, string.len(ADMIN_COMMAND)) == string.lower(ADMIN_COMMAND) then
print("[AdminCmd] Admin " .. player.Name .. " typed something starting with '".. ADMIN_COMMAND .."' but it didn't match the full command pattern: '" .. message .. "'")
end
end
end