Advertisement
DaDogeDevelopment

Warning script

May 29th, 2023 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. -- you will need to have a screen gui with just a text label in it, then place it inside your script and drag your script into ServerScriptService
  2.  
  3. local function onPlayerChatted(player, message)
  4.     local adminName = "Admin" -- Replace with the actual admin's name
  5.     local prefix = ":warn" -- The command prefix
  6.  
  7.     if message:sub(1, #prefix) == prefix then
  8.         local command = string.sub(message, #prefix + 1)
  9.         local targetPlayer, reason = command:match("(%S+)%s+(.+)")
  10.  
  11.         if targetPlayer and reason then
  12.             local target = game.Players:FindFirstChild(targetPlayer)
  13.  
  14.             if target then
  15.                 local warningCount = target:FindFirstChild("WarningCount") or Instance.new("IntValue")
  16.                 warningCount.Name = "WarningCount"
  17.                 warningCount.Parent = target
  18.                 warningCount.Value = warningCount.Value + 1
  19.  
  20.                 if warningCount.Value == 3 then
  21.                     target:Kick("You have been kicked after 3 warnings. The reason for being kicked is " .. reason .. ". If you wish to rejoin, please stop doing what you were doing.")
  22.                 else
  23.                     local warningMessage = adminName .. " has warned you for " .. reason .. ". Please stop or you will get kicked."
  24.                     local warningScreenGui = Instance.new("ScreenGui")
  25.                     local warningTextLabel = Instance.new("TextLabel")
  26.  
  27.                     warningScreenGui.Name = "WarningScreenGui"
  28.                     warningScreenGui.Parent = target.PlayerGui
  29.  
  30.                     warningTextLabel.Name = "WarningTextLabel"
  31.                     warningTextLabel.Parent = warningScreenGui
  32.                     warningTextLabel.BackgroundColor3 = Color3.new(1, 0, 0)
  33.                     warningTextLabel.Size = UDim2.new(0, 400, 0, 200)
  34.                     warningTextLabel.Position = UDim2.new(0.5, -200, 0.5, -100)
  35.                     warningTextLabel.Font = Enum.Font.SourceSansBold
  36.                     warningTextLabel.Text = warningMessage
  37.                     warningTextLabel.TextColor3 = Color3.new(1, 1, 1)
  38.                     warningTextLabel.TextScaled = true
  39.                     warningTextLabel.TextWrapped = true
  40.  
  41.                     wait(5) -- Display the warning for 5 seconds
  42.  
  43.                     warningScreenGui:Destroy()
  44.                 end
  45.             end
  46.         end
  47.     end
  48. end
  49.  
  50. game.Players.PlayerAdded:Connect(function(player)
  51.     player.Chatted:Connect(function(message)
  52.         onPlayerChatted(player, message)
  53.     end)
  54. end)
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement