:ff and :unff commands?

I’m trying to make admin commands, and for some reason the :ff and :unff commands don’t work. Here’s the part of my code for those commands.

elseif Msg:sub(1,4) == Prefix.."ff " then
				local Target = Players:FindFirstChild(Msg:sub(5))
				local Valid = CheckForTarget(Target)
				
				if Valid then
					Instance.new("ForceField", Target.Character)
				end
			elseif Msg:sub(1,4) == Prefix.."unff " then
				local Target = Players:FindFirstChild(Msg:sub(5))
				local Valid = CheckForTarget(Target)
				
				if Valid then
					Target.Character.ForceField:Destroy()
				end

maybe remove the whitespace after
"ff "
to
"ff"

Read the
Msg:sub(1,4)

The space is part of the sub.

Here’s the ff script:

if game:GetService("Players"):FindFirstChild(Msg:sub(5)) ~= nil then
    Instance.new("ForceField", game:GetService("Players"):WaitForChild(Msg:sub(5)).Character)
end

And here’s the unff one:

if game:GetService("Players"):FindFirstChild(Msg:sub(5)) ~= nil then
    if game:GetService("Players"):WaitForChild(Msg:sub(5)).Character:FindFirstChild("ForceField") ~= nil then
       game:GetService("Players"):WaitForChild(Msg:sub(5)).Character:WaitForChild("ForceField"):Destroy()
    end
end

Edit: I didn’t carefully read the Script. So you should try:

1 Like

Hello, first of all, I would use string.split so get message arguments.

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Player.Name == "ADMIN NAME HERE" then

			local Arguments = string.split(Message, " ")

			if Arguments[1] == ":ff" then
				local Target = Arguments[2]

				if game.Players:FindFirstChild(Arguments[2]) then
					local TarCharacter = Target.Character

					if not TarCharacter:FindFirstChild("ForceField") then
						local newForceField = Instance.new("ForceField")
						newForceField.Parent = TarCharacter
					end
					
				else
					return false; --> The Player does not exist or is not In-Game.
				end
			end
			
		else
			return false; --> Player is not an Administrator.
		end
	end)
end)

There were some errors, my bad. But I fixed them, and your script worked. Thanks!

Excellent you fixed it! Anyways I would use string.split().