system.runInterval(()=>{
let obj_ban = world.scoreboard.getObjective("ban-timer")
let players = world.getPlayers()
players.forEach(player=>{
let obj_ban_score = getScore(player,"ban-timer")
if (obj_ban_score > 0) {
sendMessage("ban")
obj_ban.getParticipants().forEach(p=>p.setScore(obj_ban,getScore(p,"ban-timer")-1))
}
// if (obj_ban_score < -1) player.runCommand(`scoreboard players reset @s ban-timer`)
if (obj_ban_score <= 0) obj_ban.removeParticipant(player.scoreboardIdentity)
})
},20)
#Having issues with runInterval
1 messages · Page 1 of 1 (latest)
I manually set my "ban-timer" score in game to anything above like 0, for example 10 and 100 and 1000, and it says "ban" once and then resets my score (removes from scoreboard), and also doesn't even update my in-game sidebar scoreboard for some reason
Main.js import >>
the idea is to test if scores are above 0, then remove 1 score every tick, or if that's too fast for the game to handle, every second. Once the score is 0, it removes them from the scoreboard
explained, in javascript terms:
if (player.ban-timer > 0) {
ban(player)
}
else if (player.ban-timer == 0) {
scoreboard.removeParticipant(player)
}