Advertisement
HowToRoblox

FeedbackHandler

May 30th, 2021
2,566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. local dss = game:GetService("DataStoreService")
  2. local feedbackDS = dss:GetDataStore("Feedback")
  3.  
  4. local feedbackData = {}
  5.  
  6. local success, errorMessage = pcall(function()
  7.     feedbackData = feedbackDS:GetAsync("List") or {}
  8. end)
  9.  
  10.  
  11. local re = game.ReplicatedStorage:WaitForChild("FeedbackRE")
  12.  
  13.  
  14. re.OnServerEvent:Connect(function(plr, feedback)
  15.    
  16.    
  17.     if string.len(string.gsub(feedback, " ", "")) > 0 then
  18.        
  19.         local success, errorMessage = pcall(function()
  20.             feedback = game:GetService("TextService"):FilterStringAsync(feedback, plr.UserId)
  21.             feedback = feedback:GetNonChatStringForBroadcastAsync()
  22.         end)
  23.        
  24.        
  25.         if success then
  26.            
  27.             local timeOfFeedback = os.time()
  28.             local plrSent = plr.Name
  29.            
  30.            
  31.             table.insert(feedbackData, {plrSent, feedback, timeOfFeedback})
  32.            
  33.             local success, err = pcall(function()
  34.                
  35.                 feedbackDS:SetAsync("List", feedbackData)
  36.             end)
  37.         end
  38.     end
  39. end)
  40.  
  41.  
  42. while wait(5) do
  43.    
  44.     local success, errorMessage = pcall(function()
  45.         feedbackData = feedbackDS:GetAsync("List") or {}
  46.     end)
  47.    
  48.    
  49.     game.ReplicatedStorage:WaitForChild("FeedbackFolder"):ClearAllChildren()
  50.    
  51.    
  52.     for i, feedbackInfo in pairs(feedbackData) do
  53.        
  54.         local plrName = feedbackInfo[1]
  55.         local feedback = feedbackInfo[2]
  56.         local timeSent = feedbackInfo[3]
  57.        
  58.         local timeValues = os.date("*t", timeSent)
  59.         local formattedTime = timeValues["hour"] .. ":" ..  timeValues["min"] .. ":" .. timeValues["sec"]
  60.         local formattedDate = timeValues["day"] .. "/" .. timeValues["month"] .. "/" .. timeValues["year"]
  61.         local combinedTime = formattedTime .. "  " .. formattedDate
  62.        
  63.        
  64.         local str = Instance.new("StringValue")
  65.         str.Name = plrName .. " - " .. combinedTime
  66.         str.Value = feedback
  67.        
  68.         str.Parent = game.ReplicatedStorage.FeedbackFolder
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement