Help with admin command not running

Everything else in my admin system runs, but just not this one. it runs fine in a regular script but just not in my admin system
the sender function gets player that sends it.

commands.remove = function(sender, arguments)

local playerremove = findPlayer(sender.Name)
if playerremove then

local function getPartsInRange()
	local parts = {}
	for _, part in pairs(game.Workspace:GetChildren()) do
		if part:IsA("Part") and part.Name ~= "Terrain" and part.Name ~= "AECMD" and part.Name ~= "Effecc" then
			local distance = (part.Position - playerremove.Character.Head.Position).magnitude
			if distance <= 12 then
				table.insert(parts, part)
			end
		end
	end
	return parts
end

-- Function to destroy all parts within 5 units of a player
local function destroyParts()
	print("hello")
	local parts = getPartsInRange()
	for _, part in pairs(parts) do
		part.Transparency = 1-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		wait()
		part.Transparency = part.Transparency-0.1
		part:Destroy()
	end
		destroyParts()
		end
end

end

I don’t know why it isn’t running.
its supposed to remove parts in the radius of a player.

1 Like

I think the function is not working because you are calling destroyParts() inside of the destroyParts() function instead of outside of it. So, the parts are never getting destroyed.

Maybe I am wrong, though. Your code is a little hard to read because it’s not formatted correctly.

1 Like

No, I’ve removed that before and it still didn’t work, I apologize for confusion. I forgot to remove that part.

1 Like

OK. Is the print() inside of the destroyParts() function running?

1 Like

That was a test print to see if it actually ran. it didn’t.

1 Like

do you need the findplayer() function?

1 Like

If the findPlayer() function works with the other commands, that probably is not necessary. If you are calling the destroyParts() function after you wrote it, the issue probably relies with the caller of the command. However, I do not see that you are actually calling destroyParts().

What I mean by “the caller of the command” is the script that calls the command. Also, if you want the parts to disappear at the same time, you should use task.wait() inside of the for loop – task.wait(function() -- Script the part disappearing. end).

1 Like

How would I actually call destroyParts()?

1 Like
local function destroyParts()
	print("hello")
	local parts = getPartsInRange()
	for _, part in parts do -- pairs() is not necessary.
        task.wait(function()
            -- Make the part disappear.
        end)
    end
end

destroyParts() -- Call the function outside of itself.
2 Likes

This would only run once, and never be called again. A better method is to run the function when the player chats a specific command i.e /destroyParts PlayerName. Another method for this, is to type it in a textbox with the player in mind i.e destroyParts PlayerName and then call it in the server as textbox typing is client-sided.

1 Like

Thank you for this information. This function is inside of another function that I refer to as “command.” I don’t know when the guy calls the command, but he just needs to call destroyParts() once inside of the command, from what I know.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.