Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tree Controller (Server)
- --// Services
- local Players = game:GetService("Players")
- local Storage = game:GetService("ReplicatedStorage")
- local Workspace = game:GetService("Workspace")
- local MonkeyTrees = Workspace:WaitForChild("MonkeyTrees")
- local Events = Storage:WaitForChild("Events")
- local TreeClaim = Events:WaitForChild('TreeClaim')
- --// Main Code
- Players.PlayerAdded:Connect(function(plr)
- local Deb = Instance.new("BoolValue", plr)
- Deb.Name = 'TreeDebounce'
- Deb.Value = false
- local canClaim = Instance.new("BoolValue", plr)
- canClaim.Name = 'CanClaim'
- canClaim.Value = true
- end)
- Players.PlayerRemoving:Connect(function(plr)
- -- Resetting the player own spot.
- local s,e = pcall(function()
- for _,v in pairs(MonkeyTrees:GetChildren()) do
- if v.Owner.Value == plr.Name then
- v.Owner.Value = ""
- v.OwnerUI.TextLabel.Text = 'NONE'
- end
- end
- end)
- if s then
- warn'Works when player left!'
- else
- warn(e)
- end
- end)
- TreeClaim.OnServerInvoke = function(plr, treeName, action) -- To be fired from the client.
- local Debounce = plr:WaitForChild('TreeDebounce')
- if not Debounce then warn"Fatal error! No DEBOUNCE value found in player." return end
- if action == 'Claim' then
- if not MonkeyTrees[treeName] then plr:Kick('No exploiting.') return end
- if plr:WaitForChild('CanClaim').Value == false then warn'You can not claim anything.' return end
- plr.TreeDebounce.Value = true
- plr.CanClaim.Value = false
- plr.Character.Humanoid.WalkSpeed = 16
- plr.Character.Humanoid.JumpPower = 50
- local Tree = MonkeyTrees:FindFirstChild(treeName)
- local OwnerUI = Tree['OwnerUI']
- local OwnerValue = Tree['Owner']
- OwnerValue.Value = plr.Name
- OwnerUI.TextLabel.Text = plr.Name.. ' owns this!'
- end
- if action == 'UnClaim' then -- When player leaves.
- if not MonkeyTrees[treeName] then plr:Kick('No exploiting.') return end
- if plr:WaitForChild('CanClaim').Value == false then warn'You can not claim anything.' return end
- end
- if action == 'ResetHumanoid' then
- if Debounce.Value == true then return end -- Debounce so player doesn't spam.
- -- Resetting walkspeed and jumpower if player clicks no.
- local Character = plr.Character
- local Humanoid = Character:WaitForChild('Humanoid')
- Humanoid.WalkSpeed = 16
- Humanoid.JumpPower = 50
- Debounce.Value = true
- wait(2)
- Debounce.Value = false
- end
- end
- -- Touch Handlers
- for _,v in pairs(MonkeyTrees:GetChildren()) do
- v.Touched:Connect(function(hit)
- local Player = game.Players[hit.Parent.Name]
- local wspPlr = game.Workspace[hit.Parent.Name]
- if Player:WaitForChild('TreeDebounce').Value == true then return end -- Debounce.
- if Player:WaitForChild('CanClaim').Value == false then warn'You can not claim anything.' return end
- if Player and wspPlr then
- -- Setting walkspeed.
- wspPlr.Humanoid.WalkSpeed = 0
- wspPlr.Humanoid.JumpPower = 0
- -- Other stuff
- TreeClaim:InvokeClient(Player, 'OpenUI', v.Name)
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment