I keep getting this error when using ‘for _, in pairs’. I am using JSONDecode to get the data from my website, also I am new to using “for do”
invalid argument #1 to 'pairs' (table expected, got Instance)
Here is the part of the code that the issue is coming from.
local HttpServ = game:GetService("HttpService")
local WebsiteResponse = HttpServ:GetAsync("http://toddhow.xyz/v.json")
local banData = HttpServ:JSONDecode(WebsiteResponse)
local scriptBans = {
'2533418'
}
function checkBans(plr)
local bans = banData.groupId
for _,bans in pairs(scriptBans) do
You aren’t really telling us what you want to do within the iteration or what to use it for, so we can’t assume what’s wrong other than a pointless loop with no code within the block, just put an end after this
to complete it.
If you just need to learn about it then visit these links:
Also, the error couldn’t have come from here since you’re attempting to iterate through a table in this sample - you’re trying to loop through an instance somewhere.
scriptBans is being seen as an Instance and not the table as you expect, the code should work fine so then something could have replaced your scriptBans variable.
local HttpServ = game:GetService("HttpService")
local WebsiteResponse = HttpServ:GetAsync("http://toddhow.xyz/v.json")
local banData = HttpServ:JSONDecode(WebsiteResponse)
local bans = {
'2533418'
}
function checkBans(plr)
local bans = banData.groupId
for _,bans in pairs(bans) do
local GroupServ = game:GetService("GroupService")
local groupInfo = GroupServ:GetGroupInfoAsync(banData.groupId)
if plr:IsInGroup(banData.groupId) then
plr:Kick("n\You are in a group that has been indefinitely banned by the Shake Shack Association.\n\nGroup: "..groupInfo.name.."n\n\Group Id: "..groupInfo.Id)
end
end
end
game.Players.PlayerAdded:Connect(checkBans)
for i,v in pairs(banData.groupId) do
checkBans()
end