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

More admin help?

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

✓ Accepted answer

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.

1 comment

0

uggh, i keep making some stupid mistakes. thank you!

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

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