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

More admin help?

Asked by 10 years ago

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:

01local isAdmin = {["OceanFizFiz"] = true,}
02 
03function 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
09end
10 
11function 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()
View all 32 lines...

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?

3 answers

Log in to vote
2
Answered by
SanityMan 239 Moderation Voter
10 years ago

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.

01local isAdmin = {["OceanFizFiz"] = true,}
02 
03function 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
09end
10 
11function 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()
View all 33 lines...

Try this out, and if you have more trouble, just ask.

0
uggh, i keep making some stupid mistakes. thank you! OceanFizFiz 10 — 10y
Ad
Log in to vote
0
Answered by
Usering 135
10 years ago

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:

1function 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
7end
Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
10 years ago
01local isAdmin = {["OceanFizFiz"] = true,}
02 
03function 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
09end
10 
11function 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()
View all 44 lines...

Answer this question