You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make an admin panel that when you submit the warning it will save to warnings frame in when you ht warnings under that player it will show the warnings the player was warned for -
What is the issue? Include screenshots / videos if possible!
when I submit the warning it’s not saving the warning -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I try changing the WarningSystem function to LoadWarnings
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
here is my GUI script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WarningSystem = ReplicatedStorage:WaitForChild("WarningSystem")
local Players = game:GetService("Players")
local searchBox = script.Parent.Roundify.Gradient.TextBox
local profileDisplay = searchBox.Parent:WaitForChild("Frame")
local profilePicture = profileDisplay:WaitForChild("ImageButton")
local playerNameLabel = profileDisplay:WaitForChild("TextLabel")
local nextFrame = script.Parent.Roundify.Gradient:WaitForChild("nextFrame")
local logbookFrame = nextFrame.Gradient:WaitForChild("logbook")
local warningReasonBox = nextFrame.Gradient.logbook.Gradient:WaitForChild("ReasonBox")
local submitButton = nextFrame.Gradient.logbook.Gradient:WaitForChild("SubmitButton")
local warningsList = nextFrame:WaitForChild("warnings")
local warningsButton = nextFrame.Gradient:WaitForChild("WarningsButton")
local logbookButton = nextFrame.Gradient:WaitForChild("LogbookButton")
profileDisplay.Visible = false
profilePicture.Visible = false
nextFrame.Visible = false
logbookFrame.Visible = false
warningsList.Visible = false
local playerWarnings = {}
local bannedWords = {
"badword1",
"badword2",
"badword3", -- Add more bad words as needed
}
local function censorBadWords(text)
for _, badWord in ipairs(bannedWords) do
text = text:gsub(badWord, string.rep("*", #badWord))
end
return text
end
local function addWarning(reason, playerName)
-- Censor bad words in the reason
reason = censorBadWords(reason)
if not playerWarnings[playerName] then
playerWarnings[playerName] = {}
end
table.insert(playerWarnings[playerName], reason)
local totalWarnings = #playerWarnings[playerName]
local warningLabel = Instance.new("TextLabel")
warningLabel.Text = reason
warningLabel.Size = UDim2.new(1, 0, 0, 25)
warningLabel.Position = UDim2.new(0, 0, 0.304, (totalWarnings - 1) * 30) -- Stack warnings vertically with a 30-pixel gap
warningLabel.BackgroundTransparency = 1
warningLabel.TextColor3 = Color3.new(1, 1, 1)
warningLabel.TextScaled = true
warningLabel.Parent = warningsList
end
local function updateWarningsList(playerName)
for _, child in pairs(warningsList:GetChildren()) do
if child:IsA("TextLabel") then
child:Destroy()
end
end
if playerWarnings[playerName] then
for index, warning in ipairs(playerWarnings[playerName]) do
local warningLabel = Instance.new("TextLabel")
warningLabel.Text = warning
warningLabel.Size = UDim2.new(1, 0, 0, 25)
warningLabel.Position = UDim2.new(0, 0, 0.304, (index - 1) * 30) -- Stack warnings vertically with a 30-pixel gap
warningLabel.BackgroundTransparency = 1
warningLabel.TextColor3 = Color3.new(1, 1, 1)
warningLabel.TextScaled = true
warningLabel.Parent = warningsList
end
end
end
local function getPlayerHeadshot(playerId)
return string.format("https://www.roblox.com/headshot-thumbnail/image?userId=%d&width=420&height=420&format=png", playerId)
end
local function searchAndDisplay(playerName)
if playerName == "" then
profileDisplay.Visible = false
profilePicture.Visible = false
return
end
local foundPlayer = Players:FindFirstChild(playerName)
if foundPlayer then
local userId = foundPlayer.UserId
local displayName = foundPlayer.DisplayName
profilePicture.Image = getPlayerHeadshot(userId)
playerNameLabel.Text = displayName
profileDisplay.Visible = true
profilePicture.Visible = true
profilePicture.MouseButton1Click:Connect(function()
nextFrame.Visible = not nextFrame.Visible
WarningSystem:FireServer("LoadWarnings", playerName)
end)
else
profileDisplay.Visible = false
profilePicture.Visible = false
warn("Player not found!")
end
end
submitButton.MouseButton1Click:Connect(function()
local reason = warningReasonBox.Text
local playerName = playerNameLabel.Text
if reason ~= "" and playerName ~= "" then
addWarning(reason, playerName)
WarningSystem:FireServer("AddWarning", playerName, reason)
warningReasonBox.Text = ""
end
end)
warningsButton.MouseButton1Click:Connect(function()
warningsList.Visible = true
logbookFrame.Visible = false
end)
logbookButton.MouseButton1Click:Connect(function()
warningsList.Visible = false
logbookFrame.Visible = true
end)
WarningSystem.OnClientEvent:Connect(function(action, warnings)
if action == "UpdateWarnings" then
updateWarningsList(warnings)
end
end)
searchBox:GetPropertyChangedSignal("Text"):Connect(function()
searchAndDisplay(searchBox.Text)
end)
here is my server script
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local WarningsStore = DataStoreService:GetDataStore("PlayerWarnings")
local remoteEvent = game.ReplicatedStorage:WaitForChild("WarningSystem")
local function saveWarnings(playerName, warnings)
local success, errorMessage = pcall(function()
WarningsStore:SetAsync(playerName, warnings)
end)
if not success then
warn("Failed to save warnings for " .. playerName .. ": " .. errorMessage)
end
end
local function loadWarnings(playerName)
local success, data = pcall(function()
return WarningsStore:GetAsync(playerName)
end)
if success and data then
return data
else
return {}
end
end
remoteEvent.OnServerEvent:Connect(function(player, action, playerName, reason)
if action == "AddWarning" and reason and playerName then
local warnings = loadWarnings(playerName)
table.insert(warnings, reason)
saveWarnings(playerName, warnings)
elseif action == "LoadWarnings" and playerName then
local warnings = loadWarnings(playerName)
remoteEvent:FireClient(player, "UpdateWarnings", warnings)
end
end)