Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I insert a force field into someone's character by an admin command?

I have made an admin command where you can enable a force field on someone. The admin command is not working, and I tried to print the force field's parent, but it did not print anything in the output.

if Chat:lower():sub(1, #Prefix + #"ff") == Prefix.."ff" then
	for i, v in pairs(game.Players:GetPlayers()) do
		if string.match(string.sub(Chat, 7), v.Name) then
			local ff = Instance.new("ForceField", plr.Character)
			print(ff.Parent)
		end
	end
end

How would I make it so it inserts a force field into the target?

3 comments

0

Why not try using string.gmatch()?

0

^ GMatch is an iterator function that returns the pattern when found. https://developer.roblox.com/articles/Lua-Libraries/string#gmatch

0

I fixed the indentation, and removed the extra ends.

1 answer

✓ Accepted answer

You can just use sub alone.

local code = Code:lower()

if code:sub(1, #Prefix + #('ff')) == Prefix .. 'ff' then -- checks to see if the message is "{prefix}ff"
  local cut = code:sub(#Prefix + #('ff') + 2) -- returns a cut of the original message from the start of the target in the message
  
  for _,v in pairs(game.Players:GetPlayers()) do
    local n = v.Name:lower()
    if n:sub(1, #cut) == cut then -- This can accept partial parts or a player's username. This will check if the cut is equal to a cut of the player's name
      local ff = Instance.new('ForceField')
      ff.Parent = v.Character.Torso
    end
  end
end

2 comments

0

Edit: Added explanation as a per Admin's request

0

um y is it in comment that doesn't help readability of code

This discussion is preserved as it was. New answers, comments, and votes are closed.