#(Time of day script) Script no longer working after loading into new world.

1 messages · Page 1 of 1 (latest)

undone cosmos
#

Basically, this script worked well and fine in my test world, but after loading into a fresh world I got an error saying to turn player.addTag(all_tags[world.getTimeOfDay()]) into a string, so I did. Now I'm getting no errors but the script isn't working as intended. What it's meant to do is give players a different tag at different times of day, but from what I could tell it doesn't give the intended tags which are overtime_off and overtime_on. I'm not exactly sure where I went wrong.

 const all_tags= {
}
all_tags[TimeOfDay.Day] = "overtime_off";
all_tags[TimeOfDay.Midnight] = "overtime_on";
all_tags[TimeOfDay.Night] = "overtime_on";
all_tags[TimeOfDay.Noon] = "overtime_off";
all_tags[TimeOfDay.Sunrise] = "overtime_off";
all_tags[TimeOfDay.Sunset] = "overtime_on";

system.runInterval(() => {
  world.getPlayers().forEach(player => {
    Object.values(all_tags).forEach(tag => {
      player.removeTag(tag)
    })
  })
  world.getPlayers().forEach(player => {
    player.addTag(`${all_tags[world.getTimeOfDay()]}`)
  })
}, 100)```
#

(Time of day script) Script no longer working after loading into new world.

undone cosmos
#

it's cooked

#

Im cookde

#

bro im fried

#

deep fried

undone cosmos
hexed hawk
#
}```
fallen wharf
fallen wharf
undone cosmos
#

exactly the same

#

besides

#

that one line

fallen wharf
hexed hawk
undone cosmos
hexed hawk
#

i did misread the code

fallen wharf
hexed hawk
#

yeah

fallen wharf
undone cosmos
fallen wharf
#

Basically, your world.getTimeOfDay() could return: 80, thus, all_tags[80] just returns undefined

undone cosmos
#

So if I'm understanding correctly, I did it wrong

fallen wharf
#

Use if statements and < operator ig (make a whole function for it)

undone cosmos
fallen wharf
#

yes

undone cosmos
undone cosmos
# fallen wharf yes
 const all_tags = {
}
all_tags[TimeOfDay.Day] = "overtime_off";
all_tags[TimeOfDay.Midnight] = "overtime_on";
all_tags[TimeOfDay.Night] = "overtime_on";
all_tags[TimeOfDay.Noon] = "overtime_off";
all_tags[TimeOfDay.Sunrise] = "overtime_off";
all_tags[TimeOfDay.Sunset] = "overtime_on";

system.runInterval(() => {
    var time = world.getTimeOfDay();
  world.getPlayers().forEach(player => {
      player.removeTag('overtime_on')
      player.removeTag('overtime_off')
  })
  world.getPlayers().forEach(player => {
     // Night
    if (time >= 0 && time <= 6000) {
        player.addTag(`overtime_on`)
      }

    // Midnight
    if (time >= 18000 && time <= 23000) {
        player.addTag(`overtime_on`)
      }

    // sunrise
    if (time >= 23000 && time <= 24000) {
        player.addTag(`overtime_off`)
    }
    // day
    if (time >= 0 && time <= 6000) {
        player.addTag(`overtime_off`)
    }
    // noon
    if (time >= 6000 && time <= 12000) {
        player.addTag(`overtime_off`)
    }
    // sunset
    if (time >= 12000 && time <= 13000) {
        player.addTag(`overtime_on`)
    }
  })
}, 100)```
I believe this should be right, also I'm pretty sure the all_tags const isn't necessary anymore but I kept it just incase. I didn't make it a function but this should work just as well.
#

i messed up the night and day times