LocalScript stops after setting a variable with a function

I’m currently working on my admin panel for my game, and I’m facing an issue where when I use the functions.utils.findPlayerFromPartialName(name: string) function it just stops. If you need further information please let me know I will try to reply ASAP, also I’m new to using RemoteFunctions instead of RemoteEvents since I thought they would fit my use case.

Testing output (input is “ohu”)

 22:55:50.179  Player loaded into the game, spawning Welcome GUI  -  Client - LoadGui:4
 22:55:50.549  Unfreezing player, removing GUI  -  Client - guiInit:61
 22:55:52.614   ▶ Running function to get player (explosion) (x2)  -  Client - Admin:44

My LocalScript containing my GUI and where my issues are:

local guiModule = require(game.ReplicatedStorage["Gui Library"])
local isAdminEvent = game.ReplicatedStorage.isAdmin
local themeColour = {52, 245, 255}
local commands = game.ReplicatedStorage.Commands
-- Load the gui on event load

local functions = {
	utils = {}, -- Utility functions
	commands = {} -- Functions
}

-- Generic functions

function functions.commands.explode(player : Player)
	return commands.explode:Invoke(player)
end

-- Utils

function functions.utils.findPlayerFromPartialName(name: string)
	local foundPlayers = {} -- Table to store found players
	for _, player in ipairs(game.Players:GetPlayers()) do
		if string.find(player.Name:lower(), name:lower()) then
			table.insert(foundPlayers, player)
		end
	end
	return foundPlayers
end

-- Admin GUI

isAdminEvent.OnClientEvent:Connect(function()
	local adminGui = guiModule:Window(
		"Admin Panel | Made by ohusq",
		Color3.fromRGB(unpack(themeColour)),
		Enum.KeyCode.RightShift
	)
	
	local moderationTab = adminGui:Tab("Moderation")
	local trollingTab   = adminGui:Tab("Trolling")
	
	-- Moderation
	moderationTab:Textbox("Explode player", false, function(a0: string)
		print("Running function to get player (explosion)")
		local foundPlayersTable = functions.utils.findPlayerFromPartialName(a0)
		
		if #foundPlayersTable > 1 then warn("Found multiple players!\nPlease enter the full name of the player") return end
		if (foundPlayersTable[1] == nil) then warn("No player has been found") return end
		
		print("Attempting to explode "..foundPlayersTable[1])
		functions.commands.explode(foundPlayersTable[1])
	end)
end)

My server code (can’t test since it won’t invoke)

local userIds = {2773194693} -- Whitelist for admins

local function isAdmin(userId)
	return table.find(userIds, userId) ~= nil
end

local isAdminEvent = game.ReplicatedStorage.isAdmin

game.Players.PlayerAdded:Connect(function(player)
	if isAdmin(player.UserId) then
		isAdminEvent:FireClient(player) -- Load the GUI for the localplayer
	end
end)

-- Commands handler

local commands = game.ReplicatedStorage.Commands

--[[
local explosion = Instance.new("Explosion")
	explosion.ExplosionType = Enum.ExplosionType.NoCraters -- Doesn't damage the map
	explosion.Position = workspace:FindFirstChild(player.Name)
	explosion.Hit:Connect(function(hit)
	local humanoid : Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if (humanoid) then
		humanoid:TakeDamage(humanoid.MaxHealth) -- Kills the player
	end
end)
]]
commands.explode.OnInvoke = function(localPlayer : Player, target : Player)
	if not isAdmin(localPlayer.UserId) then print(localPlayer.UserId, "is not an admin") return end
	print("Invoked explosion command", target.Name)
end

1 Like

Are you possibly filtering out warnings in the Output panel? Both of these lines warn and return, so they’d prevent the remote function from being invoked or the “Attempting to explode” line from being printed.

Nope, not an issue on the statements since my output is not filtered on anything. I even removed the if statements for testing and it’s the same result!
image image image

EDIT:

I just printed the table after loading it and it stops when trying to invoke foundPlayersTable[1].

local foundPlayersTable = functions.utils.findPlayerFromPartialName(a0)
print(foundPlayersTable) -- Prints fine
print("Attempting to explode "..foundPlayersTable[1]) -- DOESN'T PRINT

I just realised it returns the player and not player.Name, I feel so stupid.

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