Advertisement
Guest User

Legokid Source

a guest
Nov 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. --[[
  2.     Control script for the Legokid
  3. --]]
  4.  
  5. -- Constants --
  6. local RS = game:GetService("RunService")
  7. local Legokid = script.Parent
  8. local Humanoid = Legokid.Humanoid
  9. local Stop = false
  10.  
  11. local Commands = {
  12.     ["follow"] = function(...)
  13.         local Arguments = {...}
  14.        
  15.         -- Loop through all players --
  16.         for _,player in pairs(game:GetService("Players"):GetPlayers()) do
  17.             if player.Name:lower() == Arguments[1] then
  18.                 local Char = player.Character
  19.                 spawn(function()
  20.                     while Char.Humanoid.Health > 0 and Stop ~= true do
  21.                         Humanoid:MoveTo(Char.HumanoidRootPart.Position)
  22.                         RS.Heartbeat:Wait()
  23.                     end
  24.                 end)
  25.                 break  
  26.             end
  27.         end
  28.     end,
  29.     ["stop"] = function()
  30.         -- Stops the current action --
  31.         Stop = true
  32.         wait(.1)
  33.         Stop = false
  34.         --Stop = false
  35.     end
  36. }
  37.  
  38. function ParseMessage(msg)
  39.     --[[
  40.         This Function parses any given message for data
  41.         required by the commands. It will only return any
  42.         arguments and the message under certain conditions, these are:
  43.        
  44.         If the legokid isn't dead
  45.             If the parsed message begins with "legokid"
  46.                 If it has an actual command inside of it
  47.     --]]
  48.    
  49.     if Humanoid.Health > 0 then
  50.         local MsgIdentifier = msg:sub(1,7):lower()
  51.         local MsgRemainder = msg:sub(9,-1):lower() -- -1 indicating the end of the str --
  52.        
  53.         -- Check if the first 7 characters in the string are "legokid" --
  54.         if MsgIdentifier == "legokid" then
  55.             -- Loop through all commands --
  56.             for command,func in pairs(Commands) do
  57.                 local CommandEmbded = MsgRemainder:sub(1,command:len())
  58.                 local FinalRemainder = ((MsgRemainder:gsub(" ","")):sub(command:len()+1,-1))
  59.                
  60.                 -- If the command is in the beginning of MsgRemainder --
  61.                 if CommandEmbded == command then
  62.                     print("Found command", command)
  63.                     print("Remainder of command:",FinalRemainder)
  64.                    
  65.                     -- Extract arguments --
  66.                     local Arguments = FinalRemainder:split(",")
  67.                     func(unpack(Arguments))
  68.                 else
  69.                     print("Command wasn't found on this key")
  70.                 end
  71.             end
  72.         else
  73.             print("'legokid' not in beginning of command")
  74.         end
  75.     end
  76. end
  77.  
  78. game.Players.PlayerAdded:Connect(function(Player)
  79.     Player.Chatted:Connect(function(msg)
  80.         print("Chatted")
  81.         ParseMessage(msg:lower())  
  82.     end)
  83. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement