Help fixing this simple (Fire) command for my admin?

mb for not showing the broken part i just need the idea for it what i can do to make it work how it should be working.

  1. i’m just trying to use a command to execute to where when executed i can change the color of the fire that is being added to the character root part. if you need the full admin script i’m working on just ask but this is just the part i need fixed.

  2. the color i’m setting it to when using example the command “fire jj 1 1 1” it does not change the color of the fire to what i specified which is the RGB values btw, it changes it to the color black which i see why but no fix i can think of i tried countless methods to be able to change the color of the fire using the command and i promise you everything i tried did not work?

  3. i tried changing parameters i tried changing how it access’s the color using multiple methods for Color3 method and i can’t fix it no matter what i tried doing?

Below is the original script i was working with before it was turning the color black. this is just the default i was working with, and i can’t seem to figure out what else i can do to make it work how i wanted it. just if you can let me know if you got any ideas or methods at least to help with it, i just need to let the player choose what color they want the fire to be when using the cmd. so for example be able to do this “fire jj Blue” i tried using RGB and i tried using other methods of being able to change the color nothing worked it just keeps switching to default color or just be colored black.

registerCommand("fire", function(player, partialName) --already tried adding color so i removed it
	-- Send a message back to the client
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		local character = targetPlayer.Character
		if character then
			--add fire
			local fire = Instance.new("Fire")
			fire.Color = Color3.new(0.313725, 0.666667, 1)-- already tried adding a parameter for it now it's default
			fire.Size = 10
			fire.Parent = character.HumanoidRootPart
		end
	end
end)
1 Like

I would add prints after both if statements to make sure it’s getting to the change.

1 Like
  • Make sure you’re using Color3.fromRGB() for standard 0-255 color range.
  • Are you sure you’ve positioned the arguments correctly? You can use print() to check if the arguments are positioned correctly.
  • Oh, and you might also need to change the SecondaryColor of the fire too.
2 Likes

Without code context of findPlayerByPartialName or the argument structure of executed commands, a definitive solution cannot be created.

The code would work fine under the assumption that the functions get their correct arguments by name and return a correct result by name. You shall check the result of findPlayerByPartialName and the arguments correlating to the construction of the Fire instance, such as the r, g, and b values.

1 Like

so i may need to change Both SecondaryColor and Color properties? i’m going to use print statements for debugging i’m on the script again so ima try now see what i can do.

and yea they should be positioned correctly i tried a different method for the position to make sure they are where they are suppose to be. but i’m going to double check it just in case

thats literally all i can think of to what else to do to fix it. but i tried before and it didn’t help honestly but i am still going to try it again cause idk how its doing this. it’s such a simple script is it not?

local targetPlayer = findPlayerByPartialName(partialName)

Are you sure that the targetPlayer exists?

yea i am sure target player exist everything looks like it should be working that’s why it’s confusing to me. i don’t understand why every time i try changing the code to make it to where i can change the color of the fire it does Nothing but show the color black as the fire and not what i provided in the command when i used it so for example if i did “fire jj blue” or even using rgb values it always changes the fire color to black i already used different parameters and used an argument already Nothing worked. i don’t know why

can you show us your findPlayerByPartialName() function?

here’s the function for PartialName i suspected it was related to it before but couldn’t figure out how.

local function findPlayerByPartialName(partialName)
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player.Name:lower():match(partialName:lower()) then
			return player
		end
	end
	return nil
end```

seems fine, could you send your full code for further reference?

at this point i have no idea whats wrong even with the banlist command. i try using the banlist command but it says permission denied even when i do have permission i can’t figure out why it’s even doing this cause i don’t see anything wrong. everything else works perfectly fine

local remoteEvent = replicatedStorage.ExecuteCMD

-- Table to store players with permission levels
local playerPermissions = {
	["jjphariss"] = "Owner", -- Replace with player usernames and their respective permission levels
	["Username2"] = "Admin",
	-- Add more usernames and permission levels as needed
}

-- Table to store command handlers
local commandHandlers = {}

-- Define permission levels and their associated commands
local permissionLevels = {
	Owner = {"kill", "noclip", "hello", "info", "fire", "cmds","admin", "kick", "ban","unban","banlist"}, -- Owner can use all commands
	Admin = {"kill", "hello", "info", "banlist"}, -- Admin can use these commands
	Moderator = {"hello", "info", "banlist"}, -- Moderator can use these commands
}

-- Function to check if a player has permission to use a command
local function hasPermission(player, command)
	local permissionLevel = playerPermissions[player.Name]
	if permissionLevel then
		local allowedCommands = permissionLevels[permissionLevel]
		if allowedCommands then
			for _, allowedCommand in ipairs(allowedCommands) do
				if allowedCommand == command then
					return true
				end
			end
		end
	end
	return false
end

-- Function to execute a command
local function executeCommand(player, command, partialName)
	-- Check if the player has permission to use the command
	if not hasPermission(player, command) then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Find and execute the command handler
	local handler = commandHandlers[command]
	if handler then
		handler(player, partialName)
	else
		-- Send an error message for unknown commands
		remoteEvent:FireClient(player, "Unknown command: " .. command)
	end
end

-- Register a new command handler
function registerCommand(command, handler)
	commandHandlers[command] = handler
end

-- Function to find a player by partial name
local function findPlayerByPartialName(partialName)
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player.Name:lower():match(partialName:lower()) then
			return player
		end
	end
	return nil
end
-- kill command
registerCommand("kill", function(player, partialName)
	-- Find the target player by partial name
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		-- Destroy the target player's character
		local character = targetPlayer.Character
		if character then
			character:BreakJoints()
			remoteEvent:FireClient(player, "Successfully killed: " .. partialName)
		end
	else
		-- Send an error message if the target player is not found
		remoteEvent:FireClient(player, "Player not found: " .. partialName)
	end
end)

-- Table to store players who are in "NoClip" mode
local noclipPlayers = {}

-- Function to toggle NoClip mode for a player
local function toggleNoClip(player)
	if noclipPlayers[player] then
		-- Disable NoClip mode
		noclipPlayers[player] = nil
		player:LoadCharacter()
		remoteEvent:FireClient(player, "NoClip disabled.")
	else
		-- Enable NoClip mode
		noclipPlayers[player] = true
		local character = player.Character
		if character then
			-- Disable collisions for the player's character
			for _, object in ipairs(character:GetDescendants()) do
				if object:IsA("BasePart") then
					object.CanCollide = false
				end
			end
		end
		remoteEvent:FireClient(player, "NoClip enabled.")
	end
end


-- banlist command
registerCommand("banlist", function(player, partialName)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "banlist") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	local targetPlayer = findPlayerByPartialName(partialName)

	-- Fetch and display the list of banned players and their ban times
	local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
	local banList = {}
	local success, keys = pcall(function()
		return dataStore:GetSortedAsync(false, 10) -- Get the first 10 keys (bans)
	end)

	if success and keys then
		for _, key in ipairs(keys) do
			local userId = tonumber(string.gsub(key, "ban_", ""))
			local banData = dataStore:GetAsync(key)
			if banData then
				table.insert(banList, {
					UserId = userId,
					Kicker = banData.Kicker,
					BanTime = os.date("%c", banData.BanTime)
				})
			end
		end
	end

	-- Send the banlist to the client
	remoteEvent:FireClient(player, "Banned Players:\n")
	for _, banInfo in ipairs(banList) do
		local message = "UserID: " .. banInfo.UserId .. " - Banned by: " .. banInfo.Kicker .. " - Ban Time: " .. banInfo.BanTime
		remoteEvent:FireClient(player, message)
	end
end)


-- ban command
registerCommand("ban", function(player, partialName)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "ban") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Find the target player by partial name
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		-- Record the ban time using os.time()
		local banTime = os.time()

		-- Generate a unique ban key for the target player
		local banKey = "ban_" .. targetPlayer.UserId

		-- Store the ban information in a data store with the unique key
		local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
		local success, error = pcall(function()
			dataStore:SetAsync(banKey, {
				Kicker = player.Name,
				BanTime = banTime
			})
		end)

		if not success then
			print("Error saving ban player data:", error)
		end

		-- Kick the target player from the game
		targetPlayer:Kick(":Staff Member: >" .. player.Name .. "< banned you from the game")
		remoteEvent:FireClient(player, "Successfully banned: " .. partialName)
	else
		-- Send an error message if the target player is not found
		remoteEvent:FireClient(player, "Player not found: " .. partialName)
	end
end)

-- unban command
registerCommand("unban", function(player, partialName)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "unban") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Convert the partialName (username) to a UserId
	local targetUserId = nil
	local success, errorMessage = pcall(function()
		targetUserId = game:GetService("Players"):GetUserIdFromNameAsync(partialName)
	end)

	if not success or not targetUserId then
		-- Send an error message if the username is not found
		remoteEvent:FireClient(player, "Error: Username not found or invalid.")
		return
	end

	-- Generate the ban key for the target player
	local banKey = "ban_" .. targetUserId

	-- Attempt to remove the ban information from the data store
	local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
	local removeSuccess, removeError = pcall(function()
		dataStore:RemoveAsync(banKey)
	end)

	if removeSuccess then
		-- Send a message indicating that the player has been unbanned
		remoteEvent:FireClient(player, "Successfully unbanned: " .. partialName)
	else
		-- Send an error message if there was an issue removing the ban information
		remoteEvent:FireClient(player, "Error while trying to unban: " .. removeError)
	end
end)




-- ...

-- Function to check if a player is banned
local function isPlayerBanned(player)
	local banKey = "ban_" .. player.UserId
	local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
	local success, data = pcall(function()
		return dataStore:GetAsync(banKey)
	end)
	return success and data
end

-- PlayerAdded event handler
game.Players.PlayerAdded:Connect(function(player)
	if isPlayerBanned(player) then
		-- The player is banned, get the ban timestamp
		local banKey = "ban_" .. player.UserId
		local dataStore = game:GetService("DataStoreService"):GetDataStore("banData")
		local success, data = pcall(function()
			return dataStore:GetAsync(banKey)
		end)

		if success and data then
			local kickerName = data.Kicker
			local banTime = os.date("%c", data.BanTime)
			player:Kick(":Staff Member: >" .. kickerName .. "< banned you from the game at " .. banTime)
		else
			print("Error retrieving ban record for", player.Name)
			player:Kick("You are banned from the game.")
		end
	end
end)

-- ...

-- ...


--admin command
registerCommand("admin", function(player, partialName)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "admin") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Find the target player by partial name
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		-- Grant admin rank to the target player
		playerPermissions[targetPlayer.Name] = "Admin"  -- Fixed this line to update the target player's permission level
		remoteEvent:FireClient(player, "Admin rank given to: " .. partialName)
		targetPlayer.PlayerGui.AdminUI.OpenClose.Visible = true
	else
		-- Send an error message if the target player is not found
		remoteEvent:FireClient(player, "Player not found: " .. partialName)
	end
end)

--kick command
registerCommand("kick", function(player, partialName)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "kick") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Find the target player by partial name
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		-- Kick the target player from the game
		targetPlayer:Kick(":Staff Member: >" .. player.Name .. "< kicked you from the game")
		remoteEvent:FireClient(player, "Successfully kicked: " .. partialName)
	else
		-- Send an error message if the target player is not found
		remoteEvent:FireClient(player, "Player not found: " .. partialName)
	end
end)

-- noclip command
registerCommand("noclip", function(player)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "noclip") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Toggle NoClip mode for the player
	toggleNoClip(player)
end)







-- Example command handler for "hello" command
registerCommand("hello", function(player)
	-- Send a message back to the client
	remoteEvent:FireClient(player, "Hello, player!")
end)

--fire command
registerCommand("fire", function(player, partialName)
	-- Send a message back to the client
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		-- Destroy the target player's character
		local character = targetPlayer.Character
		if character then
			--add fire
			local fire = Instance.new("Fire")
			fire.Color = Color3.new(math.random(), math.random(), math.random()) --change fire color
			fire.Size = 10
			fire.Parent = character.HumanoidRootPart
		end
	end
end)

-- Example command handler for "info" command
registerCommand("cmds", function(player)
	-- Construct a list of available commands based on the player's permission level
	local permissionLevel = playerPermissions[player.Name]
	local availableCommands = {}

	if permissionLevel then
		local allowedCommands = permissionLevels[permissionLevel]
		if allowedCommands then
			for _, command in ipairs(allowedCommands) do
				table.insert(availableCommands, command)
			end
		end
	end

	-- Send an info message back to the client with the list of available commands
	local message = "Available commands: " .. table.concat(availableCommands, ", ")
	remoteEvent:FireClient(player, message)
end)



-- Example command handler for "info" command
registerCommand("info", function(player)
	-- Send an info message back to the client
	remoteEvent:FireClient(player, "This is an info message.")
end)




-- Function to send a message to a target player using a TextBox in ScreenGui
local function sendMessageToPlayer(player, partialName, message)
	-- Find the target player by partial name
	local targetPlayer = findPlayerByPartialName(partialName)
	if targetPlayer then
		-- Get the player's PlayerGui
		local playerGui = targetPlayer:FindFirstChild("PlayerGui")
		if playerGui then
			-- Find the ScreenGui, Frame, and TextBox
			local screenGui = playerGui:FindFirstChild("MessageUI")
			local frame = screenGui:FindFirstChild("Frame")
			local textBox = frame:FindFirstChild("Message")

			if screenGui and frame and textBox then
				-- Show the ScreenGui and set the message in the TextBox
				frame.Visible = true
				textBox.Text = message
				remoteEvent:FireClient(player, "Message sent to " .. partialName)
			else
				-- Send an error message if the UI components are not found
				remoteEvent:FireClient(player, "Error: UI components not found for " .. partialName)
			end
		else
			-- Send an error message if PlayerGui is not found
			remoteEvent:FireClient(player, "Error: PlayerGui not found for " .. partialName)
		end
	else
		-- Send an error message if the target player is not found
		remoteEvent:FireClient(player, "Player not found: " .. partialName)
	end
end

-- Register the new command handler
registerCommand("message", function(player, partialName, message)
	-- Check if the player has permission to use the command
	if not hasPermission(player, "message") then
		-- Send a permission denied message to the client
		remoteEvent:FireClient(player, "Permission denied.")
		return
	end

	-- Call the sendMessageToPlayer function to send the message
	sendMessageToPlayer(player, partialName, message)
end)




-- Listen for commands from clients
remoteEvent.OnServerEvent:Connect(function(player, command, partialName)
	executeCommand(player, command, partialName)
end)