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:

local isAdmin = {["OceanFizFiz"] = true,}

function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

function onChatted(message, player)
    if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character:BreakJoints()
        end
    end
    if message:sub(1,5) = "stop/" and isAdmin[player.Name] then
        victim = findPlayer(message:sub(6)
        if victim and victim.Character then
            local parts = victim.Character:GetChildren()
            for i = 1,#parts do
                parts[i].Anchored = true
            end
        end
    end
end


game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

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.

local isAdmin = {["OceanFizFiz"] = true,}

function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

function onChatted(message, player)
    if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character:BreakJoints()
        end
    elseif message:sub(1,5) == "stop/" and isAdmin[player.Name] then --two =’s to compare
        victim = findPlayer(message:sub(6)
        if victim and victim.Character then
            local parts = victim.Character:GetChildren()
            for i = 1,#parts do
                if parts[i]:IsA(“Part”) then --you must check if it is a part first
                    parts[i].Anchored = true
                end
            end
        end
    end
end


game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

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:

function findPlayer(name)
    for _,player in pairs(game.Players:GetPlayers()) do
        if player and player.Name:lower():find(name:lower()) end then
            return player
        end
    end
end
Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
10 years ago
local isAdmin = {["OceanFizFiz"] = true,}

function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

function onChatted(message, player)
    if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character:BreakJoints()
        end
    end
    if message:sub(1,5) == "stop/" and isAdmin[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            local parts = victim.Character:GetChildren()
            for i = 1,#parts do
            if parts[i]:IsA("Part") then
                parts[i].Anchored = true
            end
        end
    end
end
if message:sub(1,9) == "continue/" and isAdmin[player.Name] then -- this is an Added command To make it easier for you >:D
    victim = findPlayer(message:sub(6))
    if victim and victim.Character then
        local parts = victim.Character:GetChildren()
        for i = 1,#parts do
            if parts[i]:IsA("Part") then
                parts[i].Anchored = false
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)
end
end

Answer this question