Aquarius_Raverus

uh yay

May 4th, 2020
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. -- Tree Controller (Server)
  2.  
  3. --// Services
  4.  
  5. local Players = game:GetService("Players")
  6. local Storage = game:GetService("ReplicatedStorage")
  7. local Workspace = game:GetService("Workspace")
  8.  
  9. local MonkeyTrees = Workspace:WaitForChild("MonkeyTrees")
  10. local Events = Storage:WaitForChild("Events")
  11. local TreeClaim = Events:WaitForChild('TreeClaim')
  12.  
  13.  
  14. --// Main Code
  15.  
  16. Players.PlayerAdded:Connect(function(plr)
  17.     local Deb = Instance.new("BoolValue", plr)
  18.     Deb.Name = 'TreeDebounce'
  19.     Deb.Value = false
  20.    
  21.     local canClaim = Instance.new("BoolValue", plr)
  22.     canClaim.Name = 'CanClaim'
  23.     canClaim.Value = true
  24. end)
  25.  
  26. Players.PlayerRemoving:Connect(function(plr)
  27.     -- Resetting the player own spot.
  28.    
  29.     local s,e = pcall(function()
  30.    
  31.         for _,v in pairs(MonkeyTrees:GetChildren()) do
  32.             if v.Owner.Value == plr.Name then
  33.                 v.Owner.Value = ""
  34.                 v.OwnerUI.TextLabel.Text = 'NONE'
  35.             end
  36.         end
  37.     end)
  38.    
  39.     if s then
  40.         warn'Works when player left!'
  41.     else
  42.         warn(e)
  43.     end
  44. end)
  45.  
  46. TreeClaim.OnServerInvoke = function(plr, treeName, action) -- To be fired from the client.
  47.     local Debounce = plr:WaitForChild('TreeDebounce')
  48.     if not Debounce then warn"Fatal error! No DEBOUNCE value found in player." return end
  49.    
  50.     if action == 'Claim' then
  51.         if not MonkeyTrees[treeName] then plr:Kick('No exploiting.') return end
  52.         if plr:WaitForChild('CanClaim').Value == false then warn'You can not claim anything.' return end
  53.        
  54.         plr.TreeDebounce.Value = true
  55.         plr.CanClaim.Value = false
  56.        
  57.         plr.Character.Humanoid.WalkSpeed = 16
  58.         plr.Character.Humanoid.JumpPower = 50
  59.        
  60.         local Tree = MonkeyTrees:FindFirstChild(treeName)
  61.         local OwnerUI = Tree['OwnerUI']
  62.         local OwnerValue = Tree['Owner']
  63.        
  64.         OwnerValue.Value = plr.Name
  65.         OwnerUI.TextLabel.Text = plr.Name.. ' owns this!'
  66.     end
  67.    
  68.     if action == 'UnClaim' then -- When player leaves.
  69.         if not MonkeyTrees[treeName] then plr:Kick('No exploiting.') return end
  70.         if plr:WaitForChild('CanClaim').Value == false then warn'You can not claim anything.' return end
  71.        
  72.        
  73.     end
  74.    
  75.     if action == 'ResetHumanoid' then
  76.         if Debounce.Value == true then return end -- Debounce so player doesn't spam.
  77.                
  78.         -- Resetting walkspeed and jumpower if player clicks no.
  79.         local Character = plr.Character
  80.         local Humanoid = Character:WaitForChild('Humanoid')
  81.        
  82.         Humanoid.WalkSpeed = 16
  83.         Humanoid.JumpPower = 50
  84.        
  85.         Debounce.Value = true
  86.         wait(2)
  87.         Debounce.Value = false
  88.     end
  89. end
  90.  
  91. -- Touch Handlers
  92.  
  93. for _,v in pairs(MonkeyTrees:GetChildren()) do
  94.     v.Touched:Connect(function(hit)
  95.         local Player = game.Players[hit.Parent.Name]
  96.         local wspPlr = game.Workspace[hit.Parent.Name]
  97.        
  98.         if Player:WaitForChild('TreeDebounce').Value == true then return end -- Debounce.
  99.         if Player:WaitForChild('CanClaim').Value == false then warn'You can not claim anything.' return end
  100.        
  101.         if Player and wspPlr then
  102.             -- Setting walkspeed.
  103.            
  104.             wspPlr.Humanoid.WalkSpeed = 0
  105.             wspPlr.Humanoid.JumpPower = 0
  106.            
  107.             -- Other stuff
  108.            
  109.             TreeClaim:InvokeClient(Player, 'OpenUI', v.Name)
  110.         end
  111.     end)
  112. end
Advertisement
Add Comment
Please, Sign In to add comment