ITS_SELINASOON

No tool zone

Sep 14th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.22 KB | None | 0 0
  1. -- !!! ALL OF INFOMATION ABOUT SCRIPT CAN BE FOUND AT : https://create.roblox.com/docs
  2. -- !!! ALL OF DEVELOPER COMMUNITY POST CAN BE FOUND AT : https://devforum.roblox.com/
  3. -- !!! ALL OF DEVELOPER COMMUNITY RESOURCE FOR FREE CAN BE FOUND AT : https://devforum.roblox.com/c/resources/71
  4. -- !!! IF YOU NEED HELP PLEACE DM purplefish#9924
  5. -- Script
  6.  
  7. local StarterGui = game:GetService("StarterGui") -- Class : https://create.roblox.com/docs/reference/engine/classes/StarterGui
  8.  
  9. local Players = game:GetService("Players") -- Class : https://create.roblox.com/docs/reference/engine/classes/Players
  10. local Player = Players.LocalPlayer -- THIS CAN BE USED ON LOCAL SCRIPT | Property : https://create.roblox.com/docs/reference/engine/classes/Players#LocalPlayer
  11.  
  12. -- Tuple : https://create.roblox.com/docs/scripting/luau/tuples
  13. -- Variable : https://create.roblox.com/docs/scripting/luau/variables
  14. -- Logical Operator : https://create.roblox.com/docs/scripting/luau/operators
  15. -- Function : https://create.roblox.com/docs/scripting/luau/functions
  16. -- Control Structures : https://create.roblox.com/docs/scripting/luau/control-structures
  17. -- Scope | Block : https://create.roblox.com/docs/scripting/luau/scope
  18. -- Comment : https://create.roblox.com/docs/scripting/luau/comments
  19. -- Events : https://create.roblox.com/docs/scripting/events
  20. -- Players Container : https://create.roblox.com/docs/scripting/players/player-containers
  21.  
  22. local Connection1 = nil -- Tuple | Variable
  23. local Connection2 = nil -- Tuple | Variable
  24.  
  25. local NoToolZone = workspace.NoToolZone -- Tuple | Variable
  26.  
  27. local function UnequippedAllTool()
  28.     if Player.Character == nil then -- Check if character exist
  29.         return -- If character not exist then we exit this function early
  30.     end
  31.    
  32.     Player.Character.Humanoid:UnequipTools() -- Calling method function to unequip all tool
  33. end
  34.  
  35. local function SetToolGuiEnabled(mode : boolean)
  36.     StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,mode) -- We set backpack core gui enabled
  37. end
  38.  
  39. local function DisconnectConnection2()
  40.     if Connection2 ~= nil then -- if Connection2 does not equal to nil then
  41.         Connection2:Disconnect() -- Disconnect RBXScriptConnection so it won't affect performance
  42.         Connection2 = nil -- We set it to nil so it can be disconnected again
  43.     end
  44. end
  45.  
  46. local function DisconnectConnection1()
  47.     if Connection1 ~= nil then -- if Connection1 does not equal to nil then
  48.         Connection1:Disconnect() -- Disconnect RBXScriptConnection so it won't affect performance
  49.         Connection1 = nil -- We set it to nil so it can be disconnected again
  50.     end
  51. end
  52.  
  53. local function ConnectConnection1()
  54.     if Player.Character == nil then -- Check if character exist
  55.         return -- If character not exist then we exit this function early
  56.     end
  57.    
  58.     Connection1 = NoToolZone.Touched:Connect(function(hit : BasePart) -- We connect event that detect when No tool zone is touched (RBXScriptSignal)
  59.         if hit == Player.Character.Humanoid.RootPart then -- We check if hitted part Humanoid root part
  60.             SetToolGuiEnabled(false)
  61.             DisconnectConnection1()
  62.             ConnectConnection2()
  63.             UnequippedAllTool() -- THIS IS OPTIONAL YOU CAN DISABLE IT IF YOU WANT
  64.         end
  65.     end)
  66. end
  67.  
  68. function ConnectConnection2() -- Global function so we can call this function no matter where
  69.     if Player.Character == nil then -- Check if character exist
  70.         return -- If character not exist then we exit this function early
  71.     end
  72.    
  73.     Connection2 = NoToolZone.TouchEnded:Connect(function(hit : BasePart) -- We connect event that detect when No tool zone is touched (RBXScriptSignal)
  74.         if hit == Player.Character.Humanoid.RootPart then -- We check if hitted part Humanoid root part
  75.             SetToolGuiEnabled(true)
  76.             DisconnectConnection2()
  77.             ConnectConnection1()
  78.         end
  79.     end)
  80. end
  81.  
  82.  
  83. local function CharacterAdded(character : Model)
  84.     DisconnectConnection1() -- Disconnect event so we can refresh it again
  85.     DisconnectConnection2() -- Disconnect event so we can refresh it again
  86.    
  87.     SetToolGuiEnabled(true) -- Set back to default when respawned
  88.    
  89.     ConnectConnection1() -- Start begin listening Touched event
  90. end
  91.  
  92. local function Initialize()
  93.     Player.CharacterAdded:Connect(CharacterAdded) -- Listen for character added event then we callback the function
  94. end
  95.  
  96. Initialize() -- SYSTEM LAUNCH!!!
Advertisement
Add Comment
Please, Sign In to add comment