Advertisement
Previized

Arena ServerScript

Jan 22nd, 2021 (edited)
11,892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. --// Place this serverscript in ServerScriptService
  2. --(DO NOT TOUCH ANYTHING BELOW)
  3.  
  4. local RS = game:GetService('ReplicatedStorage')
  5. local RemoteEvent = RS:WaitForChild('ToolEvent')
  6.  
  7. game.Players.PlayerAdded:Connect(function(Player)
  8.     local Folder = Instance.new('Folder')
  9.     Folder.Name = Player.Name.. "'s Tools"
  10.     Folder.Parent = game.ReplicatedStorage
  11. end)
  12.  
  13. local function FireRemote(plr,val,item)
  14.     if val == 'steppedOn' then
  15.         local Character = plr.Character
  16.         for i,v in pairs(Character:GetChildren()) do
  17.             if v:IsA('Tool') then
  18.                 v.Parent = game.ReplicatedStorage[plr.Name.. "'s Tools"] -- if you have an equipped tool, it will place it in the folder that's created for our tools.
  19.             end
  20.         end
  21.         for i,v in pairs(plr.Backpack:GetChildren()) do
  22.             if v.Name ~= item.Name then
  23.                 if game.ReplicatedStorage[plr.Name.. "'s Tools"] then
  24.                     v.Parent = game.ReplicatedStorage[plr.Name.. "'s Tools"] -- then takes the rest of our tools that are in our backpack and places it in the folder
  25.                 end
  26.             end
  27.         end
  28.         local NewWEAPON = item:Clone() -- "item" is our tool that we get from ReplicatedStorage in the LocalScript
  29.         NewWEAPON.Parent = plr.Backpack
  30.         Character.Humanoid:EquipTool(NewWEAPON)
  31.     elseif val == 'steppedOff' then
  32.         local Character = plr.Character
  33.         for i,v in pairs(Character:GetChildren()) do
  34.             if v then
  35.                 if v:IsA('Tool') then
  36.                     if v.Name == item.Name then
  37.                         v:Destroy()
  38.                     end
  39.                 end
  40.             end
  41.         end
  42.         for i,v in pairs(plr.Backpack:GetChildren()) do
  43.             if v then
  44.                 if v:IsA('Tool') then
  45.                     if v.Name == item.Name then
  46.                         v:Destroy()
  47.                     end
  48.                 end
  49.             end
  50.         end
  51.         for i,tool in pairs(game.ReplicatedStorage[plr.Name.. "'s Tools"]:GetChildren()) do -- now we get all our tools back
  52.             tool.Parent = plr.Backpack
  53.         end
  54.     end
  55. end
  56. RemoteEvent.OnServerEvent:Connect(FireRemote)
  57. game.Players.PlayerRemoving:Connect(function(Player)
  58.     if game.ReplicatedStorage:FindFirstChild(Player.Name.. "'s Tools") then
  59.         game.ReplicatedStorage:FindFirstChild(Player.Name.. "'s Tools"):Destroy()
  60.     end
  61. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement