Advertisement
DropSquad

Custom Chat (Local)

Mar 10th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. local Player = game:GetService("Players").LocalPlayer
  2. local Module
  3.  
  4. local CreateChatModule = function(Part)
  5.     local this = {Current = nil}
  6.    
  7.     local BillboardGui = Instance.new("BillboardGui")
  8.     BillboardGui.Adornee = Part
  9.     BillboardGui.Size = UDim2.new(20, 0, 2, 0)
  10.     BillboardGui.SizeOffset = Vector2.new(0, 1)
  11.     BillboardGui.StudsOffset = Vector3.new(0, 1, 0)
  12.     BillboardGui.Parent = Part
  13.    
  14.     local Frame = Instance.new("Frame", BillboardGui)
  15.     Frame.BackgroundTransparency = 1
  16.     Frame.Size = UDim2.new(1, 0, 1, 0)
  17.    
  18.     local Container = Instance.new("Frame")
  19.     Container.Name = "Container"
  20.     Container.BackgroundTransparency = 1
  21.     Container.Size = UDim2.new(1, 0, 1, 0)
  22.     Container.ClipsDescendants = true
  23.    
  24.     local Message = Instance.new("TextLabel", Container)
  25.     Message.Name = "Message"
  26.     Message.BackgroundColor3 = Color3.new()
  27.     Message.BackgroundTransparency = 0.5
  28.     Message.Size = UDim2.new(1, 0, 1, 0)
  29.     Message.Position = UDim2.new(0, 0, 1, 0)
  30.     Message.Font = Enum.Font.SourceSans
  31.     Message.TextScaled = true
  32.    
  33.     BillboardGui.Parent = Part
  34.    
  35.     function this:RemoveChat()
  36.         local Frame = self.Current
  37.         if Frame and Frame:IsDescendantOf(workspace) then
  38.             Frame.Message:TweenPosition(
  39.                 UDim2.new(0, 0, -1, 0),
  40.                 Enum.EasingDirection.Out,
  41.                 Enum.EasingStyle.Sine, 0.5, true
  42.             )
  43.             game.Debris:AddItem(Frame, 0.5)
  44.             self.Current = nil
  45.         end
  46.     end
  47.  
  48.     function this:AddChat(Text)
  49.         self:RemoveChat()
  50.         local Frame = Container:Clone()
  51.         Frame.Size = UDim2.new(1, 0, #Text > 120 and 1 or 0.5, 0)
  52.         local Message = Frame.Message
  53.         Frame.Name = "Container"
  54.         Frame.Parent = BillboardGui.Frame
  55.         Message.Text = Text
  56.         Frame.Visible = true
  57.         Message:TweenPosition(
  58.             UDim2.new(),
  59.             Enum.EasingDirection.In,
  60.             Enum.EasingStyle.Sine, 0.5, true
  61.         )
  62.         self.Current = Frame
  63.         delay(5, function()
  64.             if self.Current == Frame then
  65.                 self:RemoveChat()
  66.             end
  67.         end)
  68.         spawn(function()
  69.             local t = tick()
  70.             while self.Current == Frame do
  71.                 wait()
  72.                 local currentTime = 5*tick()
  73.                 Message.TextColor3 = Color3.new(
  74.                     math.sin(currentTime + math.pi),
  75.                     math.sin(currentTime + math.pi/2),
  76.                     math.sin(currentTime)
  77.                 )
  78.             end
  79.         end)
  80.     end
  81.     return this
  82. end
  83.  
  84. local CharacterAdded = function(Character)
  85.     local Head = Character:WaitForChild("Head")
  86.     Module = CreateChatModule(Head)
  87. end
  88.  
  89. if Player.Character then
  90.     CharacterAdded(Player.Character)
  91. end
  92.  
  93. Player.CharacterAdded:connect(CharacterAdded)
  94.  
  95. Player.Chatted:connect(function(Message)
  96.     if Player.Character and Player.Character:FindFirstChild("Head") then
  97.         Module:AddChat(Message)
  98.     end
  99. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement