I have this report script that in this specific code allows admins to join the game that the report came from with a code that is generated for each specific server.
Issue is i keep getting a argument 2 missing or nil error for this specific line of code.
local players = game:GetService("Players")
local teleportService = game:GetService("TeleportService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("DHBRRP")
local reportModule = require(serverStorage.reportModule)
local hook = replicatedStorage.hook
local joinCode = serverStorage.code
local reportTable = {}
local admins = { --list of user IDs that can join from server reports
}
players.PlayerAdded:Connect(function(player)
if table.find(admins, tostring(player.UserId)) then
hook:FireClient(player, "admin")
end
end)
local codeMap = {}
pcall(function()
codeMap = dataStore:GetAsync("joinCode") or {}
end)
function saveData()
pcall(function()
dataStore:SetAsync("joinCode", codeMap)
end)
end
function createCode()
local code = math.random(100000, 999990)
if codeMap["ID".. tostring(code)] then
task.wait()
createCode()
end
codeMap["ID".. tostring(code)] = tostring(game.JobId)
joinCode.Value = tonumber(code)
saveData()
end
createCode()
hook.OnServerEvent:Connect(function(player, arg, contentTable)
if not player then return end
if not arg then return end
if player and arg == "sendWebhook" and contentTable ~= nil then
reportModule.sendWebhook(contentTable)
elseif player and arg == "adminJoinServer" then
pcall(function()
codeMap = dataStore:GetAsync("joinCode") or {}
end)
teleportService:TeleportToPlaceInstance(game.PlaceId, codeMap["ID".. contentTable], player) --error on this line
end
end)
game:BindToClose(function()
codeMap[joinCode.Value] = nil
saveData()
end)
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local reportPage = script.Parent
local reportSection = reportPage:WaitForChild("ReportSection")
local playerSelected = reportSection["Selected:"]
local sendReport = reportSection:WaitForChild("SubmitButton")
local confirm = reportSection:WaitForChild("ConfirmButton")
local reportReason = reportSection:WaitForChild("ReportReason"):WaitForChild("TextBox")
local scrollingFrame = reportPage:WaitForChild("PlayerList"):WaitForChild("ScrollingFrame")
local reportButton = script.Parent.Parent:WaitForChild("BottomLeft"):WaitForChild("Report"):WaitForChild("Button")
local settingsPage = reportPage.Parent:WaitForChild("Settings")
local levelsPage = reportPage.Parent:WaitForChild("LevelsUI")
local robuxShop = reportPage.Parent:WaitForChild("RobuxShop")
reportPage.Visible = false
reportSection:WaitForChild("serverID").Visible = false
reportSection:WaitForChild("join").Visible = false
local selectedPlayer
local debounce = false
local enabled = false
reportButton.Activated:Connect(function()
if settingsPage.Visible then return end
if levelsPage.Visible then return end
if robuxShop.Visible then return end
if not enabled and not debounce then
enabled = true
debounce = true
reportPage.Visible = true
for _, v in ipairs(scrollingFrame:GetChildren()) do
if not v:IsA("UIListLayout") then
v:Destroy()
end
end
for _, v in ipairs(players:GetPlayers()) do
local template = script.UserTemplate:Clone()
template.Name = v.Name
template.UserName.Text = "@".. v.Name
template.DisplayName.Text = v.DisplayName
template.UserIcon.Image = players:GetUserThumbnailAsync(v.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
template.Parent = scrollingFrame
task.wait(.2)
end
for _, v in ipairs(scrollingFrame:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Down:Connect(function()
playerSelected.Text = "Selected: ".. v.UserName.Text
selectedPlayer = v.Name
end)
end
end
debounce = false
elseif enabled and not debounce then
reportPage.Visible = false
confirm.Visible = false
enabled = false
debounce = false
reportReason.Text = ""
playerSelected.Text = "Selected:"
end
end)
local reportedUserID
sendReport.Activated:Connect(function()
if playerSelected.Text ~= "Selected:" and reportReason.Text ~= "" then
confirm.Visible = true
end
end)
confirm.Activated:Connect(function()
if not debounce then
pcall(function()
reportedUserID = players:GetUserIdFromNameAsync(tostring(selectedPlayer))
end)
replicatedStorage.hook:FireServer(
"sendWebhook", {
players.LocalPlayer.Name;
selectedPlayer;
reportReason.Text;
reportedUserID;
}
)
reportedUserID = nil
debounce = true
enabled = true
confirm.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
confirm.Text = "Report Sent!"
reportReason.Text = ""
task.wait(2.5)
reportPage.Visible = false
confirm.Visible = false
debounce = false
confirm.BackgroundColor3 = Color3.fromRGB(255, 255, 0)
confirm.Text = "Are You Sure?"
playerSelected.Text = "Selected:"
end
end)
replicatedStorage.hook.OnClientEvent:Connect(function(arg)
if not arg then return end
if arg == "admin" then
reportSection.join.Visible = true
reportSection.serverID.Visible = true
end
end)
reportSection.join.Activated:Connect(function()
replicatedStorage.hook:FireServer("adminJoinServer", tonumber(reportSection.serverID.Text))--hook remote fired from here
end)
Did you print/debug to check if this value is actually a number? Away for that, you shouldn’t use tonumber(), this value gets concatenated in the server so just pass it as a string.
that was the contentTable that needs the tonumber()
the codeMap["ID] that thats causing the error seems to be related to the dataStore stuff happening near the top of the first script.
the second argument is codeMap["ID".. contentTable], since you didn’t mention an error like “Attempt to index nil with IDblablabla”, then codeMap should be a table. the issue is contentTable, which is a variable given by any script that fired the hook remote.
looking at your localscript that fired the hook remote, this is what i saw:
so we know that contentTable is a table, which is unlikely what you are trying to achieve.
if you do "ID" .. contentTable, the result is probably going to be like IDtable: 0xblablabla.
so the conclusion is, do something with the contentTable so it can identify a value in codeMap.