Roblox Studio Argument 1 missing nil error

What is your issues?

My script is giving out ‘argument 1 missing nil’ error, and I don’t know the reason. However, the error starts on line 95. The script works fine otherwise. Basically, it checks if the module exists in the folder. If it doesn’t, it makes the specific UI invisible. But it’s not working as intended

image

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local sendkey = ReplicatedStorage.Remotes:WaitForChild("SendKeys")
local getchar = ReplicatedStorage.Remotes:WaitForChild("GetChar")
local bindFunction = ReplicatedStorage.Remotes:WaitForChild("BindFunction")
local skillsUtils = ReplicatedStorage:WaitForChild("SkillUtils")
local charData = skillsUtils:WaitForChild("CharacterData")

local debounces = {}

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:SetAttribute("Character", "None")
		character:SetAttribute("Awakening", 0)
		
		character.Parent = workspace.Entities
	end)
	player.CharacterRemoving:Connect(function()
		debounces[player] = nil
	end)
end)

sendkey.OnServerEvent:Connect(function(player, input)
	local character = player.Character or player.CharacterAdded:Wait()
	local selected = character:GetAttribute("Character")
	if debounces[player] and debounces[player][input] then return end
	debounces[player] = debounces[player] or {}
	debounces[player][input] = true

	local hotbox = player.PlayerGui:WaitForChild("Hotbox")

	for _, child in pairs(charData:GetChildren()) do
		if selected == child.Name then
			local requireChar = require(child)
			for _, abilityData in pairs(requireChar) do
				if selected and input then
					local characterFolder = script:FindFirstChild(selected)
					if characterFolder then
						local ability = characterFolder:FindFirstChild(input)
						if ability and abilityData.Key == input then
							local abilityInstance = require(ability).new(player)
							local cooldown = hotbox:WaitForChild(input).Cooldown
							if cooldown and not cooldown.Visible then
								local startSize = cooldown.Size
								local endSize = UDim2.new(0, 70, 0, -0)
								cooldown.Size = UDim2.new(0, 70.8, 0, 70)
								cooldown.Visible = true
								local tweenInfo = TweenInfo.new(abilityData.Cooldown, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
								local tween = TweenService:Create(cooldown, tweenInfo, { Size = endSize })
								tween:Play()
								abilityInstance:Play()
								tween.Completed:Wait()
								local resetTween = TweenService:Create(cooldown, tweenInfo, { Size = startSize })
								resetTween:Play()
								cooldown.Visible = false
							end
						end
					end
				end
			end
		end
	end
	debounces[player][input] = nil
end)

getchar.OnServerEvent:Connect(function(player, name)
	local hotbox = player.PlayerGui:WaitForChild("Hotbox")
	local bar = player.PlayerGui:WaitForChild("AwakeningBar")
	local character = player.Character or player.CharacterAdded:Wait()
	if not character then
		warn("Character not found for player:", player.Name)
		return
	end
	
	if character.Humanoid.Health == 100 then
		local character_Attribute = character:GetAttribute("Character")
		character:SetAttribute("Character", name)
		
		local characterFolder = script:FindFirstChild(name)

		local availableModules = {}
		for _, child in pairs(characterFolder:GetChildren()) do
			if child:IsA("ModuleScript") then
				table.insert(availableModules, child.Name)
			end
		end

		for _, child in pairs(charData:GetChildren()) do
			if child:IsA("ModuleScript") and child.Name == name then
				local requireChar = require(child)
				for _, abilityData in pairs(requireChar) do

					local hotboxChar = hotbox:FindFirstChild(abilityData.Key) -- BUG
					hotboxChar.SkillName.Text = abilityData.Name

					if requireChar["Awakening"] then
						local Charbar = bar:WaitForChild("Awakening")
						Charbar.Text = requireChar["Awakening"]
						Charbar.TextLabel.Text = requireChar["Awakening"]
					end
				end
			end
		end
		bindFunction:InvokeClient(player, availableModules)
	end
end)

Client –

local rp = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local hotbox = player:WaitForChild("PlayerGui"):WaitForChild("Hotbox")

local sendkey = rp.Remotes:WaitForChild("SendKeys")
local bindFunction = rp.Remotes:WaitForChild("BindFunction")

uis.InputBegan:Connect(function(input, processed)
	if processed then return end

	local char = player.Character or player.CharacterAdded:Wait()
	if not char then return end

	for _, v in pairs(hotbox:GetChildren()) do
		if v:IsA("Frame") then
			if input.KeyCode == Enum.KeyCode[v.Name] then
				sendkey:FireServer(v.Name)
			end
		end
	end
end)


bindFunction.OnClientInvoke = function(availableModules)
	for _, v in pairs(hotbox:GetChildren()) do
		if v:IsA("Frame") then
			v.Visible = table.find(availableModules, v.Name) ~= nil
		end
	end

	local spacing = 10
	local totalWidth = 0
	local visibleButtons = {}

	for _, v in pairs(hotbox:GetChildren()) do
		if v:IsA("Frame") then
			totalWidth = totalWidth + v.Size.X.Offset + spacing
			table.insert(visibleButtons,1,v)
		end
	end

	totalWidth = totalWidth - spacing 
	local hotboxWidth = hotbox.AbsoluteSize.X
	local startX = (hotboxWidth - totalWidth) / 2.05

	for _, v in pairs(visibleButtons) do
		v.Position = UDim2.new(0, startX, v.Position.Y.Scale, v.Position.Y.Offset)
		startX = startX + v.Size.X.Offset + spacing
	end
end

Module :

local module = {
	{Key = "One", Name = "Blood Shard", Cooldown = 1};
	{Key = "Two", Name = "Slicing Exorcism", Cooldown = 3};
	{Key = "Three", Name = "Piercing Blood", Cooldown = 5};
	["Awakening"] = "Big BROTHER!"
}
1 Like

Sorry if it’s a bit lengthy to read, I’m not good at organizing.

check if characterFolder exists:

if not characterFolder then
    warn("Character folder not found for:", name)
    return
end

Check if hotboxChar exists before accessing SkillName:

if hotboxChar then
    hotboxChar.SkillName.Text = abilityData.Name
else
    warn("Hotbox character not found for key:", abilityData.Key)
end

Think a little bit.

The argument of FindFirstChild is nil. In your code the argument sent to FindFirstChild is abilityData.Key. Logically one or several “abilityData” doesn’t own “Key”.

If I read quickly your code for “Module” I directly notice two things:

First you make mixed table and it’s a very bad pratice.

Secondly

["Awakening"] = "Big BROTHER!"

Doesn’t own “Key”.

You can simply create a new table to put all values to browse. I name it “List” for now:

local module = {
	List = {
		{Key = "One", Name = "Blood Shard", Cooldown = 1},
		{Key = "Two", Name = "Slicing Exorcism", Cooldown = 3},
		{Key = "Three", Name = "Piercing Blood", Cooldown = 5},
	},
	Awakening = "Big BROTHER!"
}

Now Module is an dictionary and the new table “List” is now an array.

Don’t forgot to update your code, now we want to browse requireChar.List:

for _, abilityData in pairs(requireChar.List) do
	local hotboxChar = hotbox:FindFirstChild(abilityData.Key) -- Now fix

You can ask me your questions if you have any.

1 Like

The ability stop working after that.

Probably because you never change the other scripts to align with the new body.

1 Like

At the line 42 of your script server, you have a condition that use abilityData.Key .
At the line 37 of the same script you have a loop with “requireChar”.

You need to do “requireChar.List” there too. You will need to change all “requireChar” to “requireChar.List”.

It’s works, thank you so much !

When i die, it’s wont work… but this error pop up.

image
image

on Line 112.

When a player character dies in your game it triggers the Player.CharacterRemoving event, which resets the debounces table for that player to nil. This is intended to clear any active cooldowns or debounces (Correct me if im wrong) associated with that player when their character is removed.

I think its that after the player character dies and debounces[player] is set to nil the issue reoccurs because the debounces[player] table is not properly reinitialized when the player respawns. which is why I think “argument 1 missing nil” error when the player tries to use abilities after respawning.

You do not find hotboxChar.

What’s the value of the property ResetOnSpawn of hotbox? If it’s true put it to false and try again.

It’s works!!! thank you so much!

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