Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited by TheeDeathCaster 5 years ago

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?

0
Why not try using string.gmatch()? DeceptiveCaster 3761 — 5y
0
^ GMatch is an iterator function that returns the pattern when found. https://developer.roblox.com/articles/Lua-Libraries/string#gmatch TheeDeathCaster 2368 — 5y
0
I fixed the indentation, and removed the extra ends. TheeDeathCaster 2368 — 5y

1 answer

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You can just use sub alone.

```lua 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 ```

0
Edit: Added explanation as a per Admin's request Rare_tendo 3000 — 5y
0
um y is it in comment that doesn't help readability of code User#24403 69 — 5y
Ad

Answer this question