Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- !!! ALL OF INFOMATION ABOUT SCRIPT CAN BE FOUND AT : https://create.roblox.com/docs
- -- !!! ALL OF DEVELOPER COMMUNITY POST CAN BE FOUND AT : https://devforum.roblox.com/
- -- !!! ALL OF DEVELOPER COMMUNITY RESOURCE FOR FREE CAN BE FOUND AT : https://devforum.roblox.com/c/resources/71
- -- !!! IF YOU NEED HELP PLEACE DM purplefish#9924
- -- Script
- local StarterGui = game:GetService("StarterGui") -- Class : https://create.roblox.com/docs/reference/engine/classes/StarterGui
- local Players = game:GetService("Players") -- Class : https://create.roblox.com/docs/reference/engine/classes/Players
- local Player = Players.LocalPlayer -- THIS CAN BE USED ON LOCAL SCRIPT | Property : https://create.roblox.com/docs/reference/engine/classes/Players#LocalPlayer
- -- Tuple : https://create.roblox.com/docs/scripting/luau/tuples
- -- Variable : https://create.roblox.com/docs/scripting/luau/variables
- -- Logical Operator : https://create.roblox.com/docs/scripting/luau/operators
- -- Function : https://create.roblox.com/docs/scripting/luau/functions
- -- Control Structures : https://create.roblox.com/docs/scripting/luau/control-structures
- -- Scope | Block : https://create.roblox.com/docs/scripting/luau/scope
- -- Comment : https://create.roblox.com/docs/scripting/luau/comments
- -- Events : https://create.roblox.com/docs/scripting/events
- -- Players Container : https://create.roblox.com/docs/scripting/players/player-containers
- local Connection1 = nil -- Tuple | Variable
- local Connection2 = nil -- Tuple | Variable
- local NoToolZone = workspace.NoToolZone -- Tuple | Variable
- local function UnequippedAllTool()
- if Player.Character == nil then -- Check if character exist
- return -- If character not exist then we exit this function early
- end
- Player.Character.Humanoid:UnequipTools() -- Calling method function to unequip all tool
- end
- local function SetToolGuiEnabled(mode : boolean)
- StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,mode) -- We set backpack core gui enabled
- end
- local function DisconnectConnection2()
- if Connection2 ~= nil then -- if Connection2 does not equal to nil then
- Connection2:Disconnect() -- Disconnect RBXScriptConnection so it won't affect performance
- Connection2 = nil -- We set it to nil so it can be disconnected again
- end
- end
- local function DisconnectConnection1()
- if Connection1 ~= nil then -- if Connection1 does not equal to nil then
- Connection1:Disconnect() -- Disconnect RBXScriptConnection so it won't affect performance
- Connection1 = nil -- We set it to nil so it can be disconnected again
- end
- end
- local function ConnectConnection1()
- if Player.Character == nil then -- Check if character exist
- return -- If character not exist then we exit this function early
- end
- Connection1 = NoToolZone.Touched:Connect(function(hit : BasePart) -- We connect event that detect when No tool zone is touched (RBXScriptSignal)
- if hit == Player.Character.Humanoid.RootPart then -- We check if hitted part Humanoid root part
- SetToolGuiEnabled(false)
- DisconnectConnection1()
- ConnectConnection2()
- UnequippedAllTool() -- THIS IS OPTIONAL YOU CAN DISABLE IT IF YOU WANT
- end
- end)
- end
- function ConnectConnection2() -- Global function so we can call this function no matter where
- if Player.Character == nil then -- Check if character exist
- return -- If character not exist then we exit this function early
- end
- Connection2 = NoToolZone.TouchEnded:Connect(function(hit : BasePart) -- We connect event that detect when No tool zone is touched (RBXScriptSignal)
- if hit == Player.Character.Humanoid.RootPart then -- We check if hitted part Humanoid root part
- SetToolGuiEnabled(true)
- DisconnectConnection2()
- ConnectConnection1()
- end
- end)
- end
- local function CharacterAdded(character : Model)
- DisconnectConnection1() -- Disconnect event so we can refresh it again
- DisconnectConnection2() -- Disconnect event so we can refresh it again
- SetToolGuiEnabled(true) -- Set back to default when respawned
- ConnectConnection1() -- Start begin listening Touched event
- end
- local function Initialize()
- Player.CharacterAdded:Connect(CharacterAdded) -- Listen for character added event then we callback the function
- end
- Initialize() -- SYSTEM LAUNCH!!!
Advertisement
Add Comment
Please, Sign In to add comment