Hey. I was making a script that would check if a player is still on the hill while a stopwatch was counting how long they were on the hill. The problem is that the script doesn’t detect when the table’s values changes. Any help is appreciated, thanks ![]()
local hill = game.Workspace.Hill
local status = hill.Status
local holder = hill.Holder
local playersOnHill = {}
local function counter(player, intVal, Table)
print(Table)
local count = 0
while count < 5 do
local function getUpdatedTable(tab)
if table.find(tab, tostring(player.Name)) then
return true
end
end
wait(1)
count = count + 1
intVal.Value = count
local isPlayerOnHill = getUpdatedTable(playersOnHill)
if isPlayerOnHill == true then
intVal:Destroy()
break
end
if count == 5 then
break
end
end
status.Value = "Held by: ".. player.Name
holder.Value = player.Name
intVal:Destroy()
end
while wait(1) do
local touchingParts = GetTouchingParts(hill)
for i,v in pairs(touchingParts) do
wait()
if v.Parent:FindFirstChild('Humanoid') then
if not table.find(playersOnHill, v.Parent.Name) then
table.insert(playersOnHill, v.Parent.Name)
end
end
end
if #playersOnHill == 1 then
if game.Players:FindFirstChild(playersOnHill[1]):FindFirstChild('TimeTaking') == nil and holder.Value ~= playersOnHill[1] then
status.Value = "Contested"
local stopWatch = Instance.new('IntValue')
stopWatch.Name = "TimeTaking"
stopWatch.Value = 0
stopWatch.Parent = game.Players:FindFirstChild(playersOnHill[1])
counter(game.Players:FindFirstChild(playersOnHill[1]), stopWatch, playersOnHill)
end
end
if #playersOnHill == 0 then
for i,v in pairs(game:GetService('Players'):GetPlayers()) do
wait()
local intValue = v:FindFirstChild('TimeTaking')
if intValue then
intValue:Destroy()
end
end
end
for i,v in pairs(playersOnHill) do
wait()
table.remove(playersOnHill, 1)
end
end