I’m attempting to make a code in which hold warnings given to users, but whenever I warn someone, the value could +2 or +3, rather than +1. What’s the concurrent issue? I’m using ipairs and that may be the case of why it’s not functioning as intended. The code’s:
--[ Variables
local prefix = "!"
local groupId = 3810524
local rank = 4
--[ Setup
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if plr:GetRankInGroup(groupId) <= rank then
local ui = script.WarningGUI:Clone()
ui.Parent = char.Head
end
plr.Chatted:Connect(function(msg)
if plr:GetRankInGroup(groupId) >= rank then
local msg = string.lower(msg)
local splitMsg = msg:split(" ")
local arg1 = splitMsg[1]
local cmd = arg1:split(prefix)[2]
local plrToWarn = splitMsg[2]
local found
if cmd == "warn" then
local reason = {}
for reasonE in string.gmatch(msg, "[^%s]+") do
table.insert(reason, reasonE)
end
reason = table.concat(reason, " ", 3)
local filter = game:GetService("TextService"):FilterStringAsync(reason, plr.UserId):GetNonChatStringForBroadcastAsync()
for _, i in ipairs(game.Players:GetPlayers()) do
if i.Name:lower():sub(1, #plrToWarn) == plrToWarn then
found = i
break
end
end
if found then
local ui = found.Character.Head.WarningGUI
local cWarnings = ui.Warnings
cWarnings.Value = cWarnings.Value + 1
ui.WarningLabel.Text = "Warning ["..cWarnings.Value.."] - "..filter
end
end
end
end)
end)
end)