earlier I asked a question about admin commands and someone told me to look at a wiki article and come back if I had questions. I have a question about a command i want to make and here is what I tried to do:
01 | local isAdmin = { [ "OceanFizFiz" ] = true , } |
02 |
03 | function findPlayer(name) |
04 | for _, player in ipairs (game.Players:GetPlayers()) do |
05 | if player.Name:lower() = = name:lower() then |
06 | return player |
07 | end |
08 | end |
09 | end |
10 |
11 | function onChatted(message, player) |
12 | if message:sub( 1 , 5 ) = = "kill/" and isAdmin [ player.Name ] then |
13 | victim = findPlayer(message:sub( 6 )) |
14 | if victim and victim.Character then |
15 | victim.Character:BreakJoints() |
i wanted to make a command that stops a player so they can’t move. I think the anchor part of things would do that but it didn’t work for me. Can someone tell me why it didn’t work please?
There are a few mistakes in this piece of code. I have pointed them out with comments in a fixed version of your script. Look at the comments so you know what you did, and you can learn from it.
01 | local isAdmin = { [ "OceanFizFiz" ] = true , } |
02 |
03 | function findPlayer(name) |
04 | for _, player in ipairs (game.Players:GetPlayers()) do |
05 | if player.Name:lower() = = name:lower() then |
06 | return player |
07 | end |
08 | end |
09 | end |
10 |
11 | function onChatted(message, player) |
12 | if message:sub( 1 , 5 ) = = "kill/" and isAdmin [ player.Name ] then |
13 | victim = findPlayer(message:sub( 6 )) |
14 | if victim and victim.Character then |
15 | victim.Character:BreakJoints() |
Try this out, and if you have more trouble, just ask.
This is a bit off topic, but the way you find players will only find the player with the exact, lowercased name that you inputted. Replace your findPlayers function with this:
1 | function findPlayer(name) |
2 | for _,player in pairs (game.Players:GetPlayers()) do |
3 | if player and player.Name:lower():find(name:lower()) end then |
4 | return player |
5 | end |
6 | end |
7 | end |
01 | local isAdmin = { [ "OceanFizFiz" ] = true , } |
02 |
03 | function findPlayer(name) |
04 | for _, player in ipairs (game.Players:GetPlayers()) do |
05 | if player.Name:lower() = = name:lower() then |
06 | return player |
07 | end |
08 | end |
09 | end |
10 |
11 | function onChatted(message, player) |
12 | if message:sub( 1 , 5 ) = = "kill/" and isAdmin [ player.Name ] then |
13 | victim = findPlayer(message:sub( 6 )) |
14 | if victim and victim.Character then |
15 | victim.Character:BreakJoints() |