Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Control script for the Legokid
- --]]
- -- Constants --
- local RS = game:GetService("RunService")
- local Players = game:GetService("Players")
- local RepStor = game:GetService("ReplicatedStorage")
- local Extras = require(RepStor.Extras)
- local Legokid = script.Parent
- local Humanoid = Legokid.Humanoid
- local Stop = false
- local Rad = math.rad
- local RNG = Random.new()
- local Commands = {
- ["follow"] = function(...)
- local Arguments = {...}
- if Arguments[1] then
- -- Make the legokid stop following any preselected player --
- Stop = true
- wait(.1)
- Stop = false
- -- Loop through all players --
- for _,player in pairs(Players:GetPlayers()) do
- if player.Name:lower() == Arguments[1] then
- local Char = player.Character
- spawn(function()
- while Char.Humanoid.Health > 0 and Stop ~= true do
- Humanoid:MoveTo(Char.HumanoidRootPart.Position)
- RS.Heartbeat:Wait()
- end
- end)
- break
- end
- end
- end
- end,
- ["stop"] = function()
- -- Stops the current action --
- Stop = true
- wait(.1)
- Stop = false
- end,
- ["jump"] = function()
- Humanoid.Jump = true
- end,
- ["unequip"] = function()
- local RiS = Legokid.Torso["Right Shoulder"]
- -- If the character has a tool equiped --
- if Legokid:FindFirstChildOfClass("Tool") then
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
- RS.Heartbeat:Wait()
- end
- end
- -- Unequip any tools already equipped --
- Humanoid:UnequipTools()
- end,
- ["equip"] = function(...)
- local Arguments = {...}
- if Arguments[1] then
- local Tool = RepStor:FindFirstChild(Arguments[1]):Clone()
- local RiS = Legokid.Torso["Right Shoulder"]
- -- If the character has a tool equiped, move it back to the default arm rotation21 --
- if Legokid:FindFirstChildOfClass("Tool") then
- -- Unequip any tools already equipped --
- Humanoid:UnequipTools()
- -- Move the arm --
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(-6))
- RS.Heartbeat:Wait()
- end
- end
- -- Equip the given tool --
- if Tool then
- for i = 1,90,6 do
- RiS.C0 = RiS.C0*CFrame.Angles(Rad(0),Rad(0),Rad(6))
- RS.Heartbeat:Wait()
- end
- Humanoid:EquipTool(Tool)
- wait(1)
- end
- end
- end,
- ["attack"] = function(...)
- local Arguments = {...}
- local Tool = Legokid:FindFirstChildOfClass("Tool")
- -- If the player supplied a player to follow --
- if Arguments[1] then
- if Tool then
- -- If the player exists --
- for _,Player in pairs(Players:GetPlayers()) do
- if Player.Name:lower() == Arguments[1] then
- local Char = Player.Character
- -- Make the legokid stop following any preselected player --
- Stop = true
- wait(.1)
- Stop = false
- -- Follow the player until conditions are met --
- spawn(function()
- while Char.Humanoid.Health > 0 and Stop == false do
- Humanoid:MoveTo(Char.HumanoidRootPart.Position)
- wait()
- end
- end)
- -- Attack the player until conditions are met --
- spawn(function()
- while Char.Humanoid.Health > 0 and Stop == false do
- local Dist = Extras:GetDistance(Legokid.HumanoidRootPart,Char.HumanoidRootPart)
- if Dist <= Tool.Configuration.AttackRange.Value then
- -- Tool specific attacks --
- if Tool.Name == "sword" then
- local SwordMove = RNG:NextInteger(1,2)
- -- Lunge, and swing --
- if SwordMove == 1 then
- Tool:Activate()
- elseif SwordMove == 2 then
- Tool:Activate()
- wait(.2)
- Tool:Activate()
- end
- else
- print("E")
- end
- end
- wait(.3)
- end
- end)
- end
- end
- end
- end
- end
- }
- function ParseMessage(msg)
- --[[
- This Function parses any given message for data
- required by the commands. It will only return any
- arguments and the message under certain conditions, these are:
- If the legokid isn't dead
- If the parsed message begins with "legokid"
- If it has an actual command inside of it
- --]]
- if Humanoid.Health > 0 then
- local MsgIdentifier = msg:sub(1,7):lower()
- local MsgRemainder = msg:sub(9,-1):lower() -- -1 indicating the ending of the str --
- -- Check if the first 7 characters in the string are "legokid" --
- if MsgIdentifier == "legokid" then
- -- Loop through all commands --
- for command,func in pairs(Commands) do
- local CommandEmbded = MsgRemainder:sub(1,command:len())
- local FinalRemainder = ((MsgRemainder:gsub(" ","")):sub(command:len()+1,-1))
- -- If the command is in the beginning of MsgRemainder --
- if CommandEmbded == command then
- print("Found command", command)
- print("Remainder of command:",FinalRemainder)
- -- Extract arguments --
- local Arguments = FinalRemainder:split(",")
- func(unpack(Arguments))
- else
- print("Command wasn't found on this key")
- end
- end
- else
- print("'legokid' not in beginning of command")
- end
- end
- end
- game.Players.PlayerAdded:Connect(function(Player)
- Player.Chatted:Connect(function(msg)
- print("Chatted")
- ParseMessage(msg:lower())
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement