Advertisement
Cakey3101

King Of The Hill System

Jun 13th, 2025
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local Values = script.Parent.Values
  4. local Area = script.Parent.Area
  5.  
  6. local HillPlayers = {}
  7.  
  8. local function OnEnterZone(Base)
  9.     local Character = Base.Parent
  10.     if Character and Character:FindFirstChild("Humanoid") then
  11.         local Player = Players:GetPlayerFromCharacter(Character)
  12.         if Player and not table.find(HillPlayers, Player) then
  13.             table.insert(HillPlayers, Player)
  14.             if Values.HasKing.Value then
  15.                 Values.OtherKings.Value = true
  16.             else
  17.                 Values.HasKing.Value = true
  18.             end
  19.         end
  20.     end
  21. end
  22.  
  23. local function OnExitZone(Base)
  24.     local Character = Base.Parent
  25.     if Character and Character:FindFirstChild("Humanoid") then
  26.         local Player = Players:GetPlayerFromCharacter(Character)
  27.         local Index = table.find(HillPlayers, Player)
  28.         if Player and Index then
  29.             table.remove(HillPlayers, Index)
  30.         end
  31.     end
  32. end
  33.  
  34. Area.Touched:Connect(OnEnterZone)
  35. Area.TouchEnded:Connect(OnExitZone)
  36.  
  37. task.spawn(function()
  38.     while task.wait(1) do
  39.         for _, Player in ipairs(Players:GetPlayers()) do
  40.             if table.find(HillPlayers, Player) then
  41.                 if #HillPlayers == 1 then
  42.                     Values.HasKing.Value = true
  43.                     Values.OtherKings.Value = false
  44.                     Player.leaderstats.Gems.Value += 1
  45.                 elseif #HillPlayers > 1 then
  46.                     Values.HasKing.Value = false
  47.                     Values.OtherKings.Value = true
  48.                 end
  49.             end
  50.         end
  51.     end
  52. end)
Tags: robloxsutdio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement