Advertisement
Guest User

Event Receiver

a guest
Feb 23rd, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.79 KB | None | 0 0
  1. local but = script.Parent
  2. local isBuilding = script.Building --just so that external scripts can see this shtuff
  3. local bID = script.BlockID --currently we arn't going to do much with this until we get other scripts/blocks
  4. local typing = false
  5. local con = but.Parent
  6. local pGUI = con.Parent
  7. local plr = pGUI.Parent
  8. local tGui = con.BuildHelp
  9. local char = workspace:WaitForChild(plr.Name)
  10. local coms = game.ReplicatedStorage.Build
  11. local access = game.ReplicatedStorage.BuildAccess
  12. local bind = con.Parent:WaitForChild("BuildMessage")
  13. local dDebounce = true
  14. local dTimer = 3
  15. local passes = {
  16.     "ToolEquip",
  17.     "ToolUnequip",
  18.     }
  19. local Image1 = "rbxassetid://2220069704"
  20. local Image2 = "rbxassetid://2220069316"
  21.  
  22. local function tutorial()
  23.     if isBuilding.Value then
  24.         tGui:TweenPosition(UDim2.new(0.91, 0, 0.14, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 1)
  25.         wait(0.1)
  26.     elseif not isBuilding.Value then
  27.         tGui:TweenPosition(UDim2.new(1.17, 0, 0.14, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 1)
  28.         wait(0.1)
  29.     end
  30. end
  31.  
  32. local function activate()
  33.     if isBuilding.Value == false then
  34.         coms:FireServer(passes[1])
  35.         --isBuilding.Value = not isBuilding.Value
  36.     elseif isBuilding.Value == true then
  37.         coms:FireServer(passes[2])
  38.         --isBuilding.Value = not isBuilding.Value
  39.     end
  40. end
  41.  
  42. local function message(text)
  43.     dDebounce = false
  44.     wait() --that's a whole lotta waits
  45.     local s = script.BuildDialogue:Clone()
  46.     s.Parent = con
  47.     if text then
  48.         s.TextLabel = text
  49.     end
  50.     s:TweenPosition(UDim2.new(0.125, 0, 0.625, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.5)
  51.     wait(dTimer)
  52.     s:TweenPosition(UDim2.new(-0.126, 0, 0.625, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5)
  53.     wait(0.5)
  54.     s:Destroy()
  55.     dDebounce = true
  56.     --print("Boom, message done")
  57. end
  58.  
  59. local function scan()
  60.     while true do
  61.         wait()
  62.        
  63.         --if the build tutorial is out when not building or vice versa
  64.         if isBuilding.Value == false and tGui.Position == UDim2.new(0.91, 0, 0.14, 0) then
  65.             tutorial()
  66.         elseif isBuilding.Value == true and tGui.Position == UDim2.new(1.17, 0, 0.14, 0) then
  67.             tutorial()
  68.         end
  69.        
  70.         --if the gui hides itself
  71.         if but.Parent.Enabled == false then
  72.             isBuilding.Value = false
  73.             but.Image = Image2
  74.             if char:FindFirstChild("Hammer") then
  75.                 coms:FireServer(passes[2])
  76.             end
  77.         end
  78.        
  79.         --if the player gets an orb during buildmode
  80.         local c = access:InvokeServer("Tools?")
  81.         repeat wait() until c
  82.         if c then
  83.             local low = string.lower(c.Name)
  84.             if string.find(low, "orb") then
  85.                 isBuilding.Value = false
  86.                 but.Image = Image2
  87.             end
  88.         end
  89.     end
  90. end
  91.  
  92. isBuilding.Changed:Connect(function() --tutorial
  93.     tutorial()
  94. end)
  95.  
  96. coms.OnClientEvent:Connect(function(pass)
  97.     if pass == passes[1] then
  98.         isBuilding.Value = true
  99.         but.Image = Image1
  100.     elseif pass == passes[2] then
  101.         isBuilding.Value = false
  102.         but.Image = Image2
  103.     end
  104. end)
  105.  
  106. print("Connecting Event!")
  107. bind.Event:Connect(function(mess) --client access to messaging
  108.     print("Recieved an Event")
  109.     if dDebounce then
  110.         print("Doing the message!")
  111.         message(mess)
  112.     end
  113. end)
  114. print("Event Connected!")
  115.  
  116. plr.CharacterAdded:Connect(function(char)
  117.     char.ChildRemoved:Connect(function(child)
  118.         if child.Name == 'Hammer' then
  119.         --  coms:FireServer(passes[2])
  120.             isBuilding.Value = false
  121.             but.Image = Image2
  122.         end
  123.     end)
  124. end)
  125.  
  126. coms.OnClientEvent:Connect(function(pass)
  127.     if pass == "TooMany" and dDebounce then
  128.         message()
  129.     elseif pass == "NoWood" and dDebounce then
  130.         message("You have used all of your wood!")
  131.     end
  132. end)
  133.  
  134. game:GetService("UserInputService").InputBegan:Connect(function(key, gpe)
  135.     if gpe then return end
  136.     if (key.KeyCode == Enum.KeyCode.B or key.KeyCode == Enum.KeyCode.ButtonB) then --both keyboard and gamepad
  137.         if but.Parent.Enabled then
  138.             activate()
  139.         end
  140.     end
  141. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement