Advertisement
mfx832

Untitled

Jan 12th, 2025 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. -- Server Side
  2. local players = game:GetService("Players")
  3. local rep = game:GetService("ReplicatedStorage")
  4.  
  5. local PlayersFolder = workspace:FindFirstChild("Players")
  6. if not PlayersFolder then
  7.     PlayersFolder = Instance.new("Folder")
  8.     PlayersFolder.Name = "Players"
  9.     PlayersFolder.Parent = workspace
  10. end
  11.  
  12. game.Players.PlayerAdded:Connect(function(player)
  13.     player.CharacterAdded:Connect(function(character)
  14.         local playerFolder = PlayersFolder:FindFirstChild(player.Name)
  15.         if not playerFolder then
  16.             playerFolder = Instance.new("Folder")
  17.             playerFolder.Name = player.Name
  18.             playerFolder.Parent = PlayersFolder
  19.  
  20.             local inventory = Instance.new("Folder")
  21.             inventory.Name = "Inventory"
  22.             inventory.Parent = playerFolder
  23.         end
  24.  
  25.         character.Parent = playerFolder
  26.         character:WaitForChild("Humanoid").Died:Connect(function()
  27.             player.CharacterAdded:Wait().Parent = playerFolder
  28.         end)
  29.     end)
  30. end)
  31.  
  32. local cd = {}
  33.  
  34.  
  35.  
  36. rep.Items.OnServerEvent:Connect(function(player, status)
  37.     local char = player.Character
  38.     local inventory = game.Workspace.Players[player.Name].Inventory
  39.     if char then
  40.         if status == "Insert" and not table.find(cd, player) then
  41.             local Lantern = rep.Lantern.Lantern:Clone()
  42.             local motor6 = rep.Lantern.Handle:Clone()
  43.            
  44.             motor6.Part0 = char["Right Arm"]
  45.             motor6.Part1 = Lantern.Handle
  46.            
  47.             motor6.Parent = char["Right Arm"]
  48.             Lantern.Parent = inventory
  49.            
  50.             rep.Animation:FireClient(player, "Lantern", "Equip")
  51.            
  52.            
  53.         elseif status == "Remove" then
  54.             table.insert(cd, player)
  55.             task.delay(0.5,function()
  56.                 table.remove(cd, table.find(cd, player))
  57.             end)
  58.            
  59.             if char["Right Arm"]:FindFirstChild("Handle1") then
  60.                 char["Right Arm"].Handle:Destroy()
  61.             end
  62.            
  63.             inventory.Lantern:Destroy()
  64.            
  65.             rep.Animation:FireClient(player, "Lantern", "UnEquip")
  66.            
  67.         elseif table.find(cd, player) then
  68.             rep.Notifications:FireClient(player, "⚠️ Please wait a moment after unequiping the item.", "Warn")
  69.         end
  70.     end
  71. end)
  72.  
  73. --------------------------------------------------------------------------------------------------------------------------------
  74.  
  75. -- Client Side
  76. local UIS = game:GetService("UserInputService")
  77. local rep = game:GetService("ReplicatedStorage")
  78. local player = game.Players.LocalPlayer
  79. local char = player.Character
  80. local animator: Animator = char:WaitForChild("Humanoid"):WaitForChild("Animator")
  81. local notifications = require(player.PlayerGui.NotificationSystem.NotificationModule)
  82.  
  83. local HoldLantern = animator:LoadAnimation(rep.Animations.Tools.HoldItem)
  84. local OpenLantern = animator:LoadAnimation(rep.Animations.Tools.LanternOpen)
  85.  
  86. UIS.InputBegan:Connect(function(key,gpe)
  87.     if gpe then return end
  88.    
  89.     if key.KeyCode == Enum.KeyCode.B then
  90.         if workspace.Players[player.Name].Inventory:FindFirstChild("Lantern") then
  91.             rep.Items:FireServer("Remove")
  92.         else
  93.             rep.Items:FireServer("Insert")
  94.         end
  95.     end
  96. end)
  97.  
  98. rep.Animation.OnClientEvent:Connect(function(Tool, Status)
  99.     if Status == "Equip" then
  100.         if Tool == "Lantern" then
  101.             OpenLantern:Play()
  102.             HoldLantern:Play()
  103.         end
  104.     elseif Status == "UnEquip" then
  105.         if Tool == "Lantern" then
  106.             HoldLantern:Stop()
  107.             OpenLantern:Stop()
  108.         end
  109.     end
  110. end)
  111.  
  112.  
  113. rep.Notifications.OnClientEvent:Connect(function(Text, Status)
  114.     if Status == "Warn" then
  115.         notifications.NewWarning(Text, 1)
  116.     elseif Status == "Success" then
  117.         notifications.NewSucess(Text, 1)
  118.     elseif Status == "Error" then
  119.         notifications.NewError(Text, 1)
  120.     end
  121. end)
  122.  
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement