function Die(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.round(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}

    StartupEvents.registry('palladium:abilities', (event) => {
        event.create('heroes:intuitive_replication')
            .icon(palladium.createItemIcon('palladium:vibranium_circuit'))

            .tick((entity, entry, holder, enabled) => {
                if (enabled) {

                    let username = entity.getGameProfile().getName();
					let username_true = username.toLowerCase();
                    let scoreboard = Utils.server.scoreboard;
					let power_max = global.power_amount;
            

							
			const targets = entity.serverLevel().getEntities(entity, AABB.ofSize(entity.position(), 15, 15, 15)).toArray();
                for (let j = 0; j < targets.length; j++) {
		if (targets[j].isPlayer()) {
			let power_amount = 0
			let username_target = targets[j].getGameProfile().getName();
			 let bond = entity.persistentData[username + "_" + username_target + "_Bond"]
			 if (bond == null) {
				 entity.persistentData[username + "_" + username_target + "_Bond"] = 0
			 }
			
			for (let power_list = 0; power_list <= power_max; power_list++) {
				let power_cap = global['ability_' + power_list];
				let power = power_cap.toString().toLowerCase();
				let scoreboard = Utils.server.scoreboard;
				
				let scoreboard_obj_temp_x = scoreboard.getObjective('Powers.Intuitive.' + power_cap);
							if (scoreboard_obj_temp_x != null) {
							let score_temp = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_temp_x);
							let value_temp = score_temp.getScore();
					let scoreboard_hold_7 = scoreboard.getObjective("Powers." + power_cap);
			if (scoreboard_hold_7 != null) {
                    let score_hold_7 = scoreboard.getOrCreatePlayerScore(username_target, scoreboard_hold_7);
                    let value_hold_7 = score_hold_7.getScore();
					if (value_hold_7 >= 1 && value_temp == 0) {
						power_amount += 1
						
							}
						}
					}
				}
				
				if (bond == 36000) {
						let chance = (Die(0, power_max));
				for (let failsafe = 1; failsafe <= 10; failsafe++) {
					if (failsafe == 9) {
						chance = 0
					}
					for (let power_list = chance; power_list <= power_max; power_list++) {
						let power = global['ability_' + power_list];
						
							let scoreboard_obj_temp = scoreboard.getObjective('Powers.Intuitive.' + power);
							if (scoreboard_obj_temp != null) {
							let score_temp = scoreboard.getOrCreatePlayerScore(username, scoreboard_obj_temp);
							let value_temp = score_temp.getScore();
							
							let scoreboard_obj_temp_1 = scoreboard.getObjective('Powers.' + power);
							if (scoreboard_obj_temp_1 != null) {
							let score_temp_1 = scoreboard.getOrCreatePlayerScore(username_target, scoreboard_obj_temp_1);
							let value_temp_1 = score_temp_1.getScore();
							
							
					if (power != 'Ability_Absorption' && power != 'Ability_Transferal' && power != 'Interplay' && power != 'Catalyst' && power != 'Intuitive_Aptitude' && value_temp_1 >= 1 && value_temp == 0) {
							
						entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players set @s Powers.Intuitive." + power + " 1");
						
						entity.server.runCommandSilent("execute as " + username + " at @s run tellraw @s [\"\",{\"text\":\"Your bond with " + username_target + " has grown and you have gained " + power + "\",\"bold\":true,\"color\":\"dark_purple\"}]");
						
					if (power == 'Ability_Replication') {
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation .IntuitiveHold_1 Heroes.Intuitive.Study = " + username_target + " Heroes.Replication.Slots.True");

					entity.server.runCommandSilent("execute as " + username + " at @s if score .IntuitiveHold_1 Heroes.Intuitive.Study > @s Heroes.Replication.Slots.Intuitive run scoreboard players operation @s Heroes.Replication.Slots.Intuitive = .IntuitiveHold_1 Heroes.Intuitive.Study");
					
					entity.server.runCommandSilent("scoreboard players reset .IntuitiveHold_1 Heroes.Intuitive.Study");
					}
					
					if (power == 'Levitation') {
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation .IntuitiveHold_1 Heroes.Intuitive.Study = " + username_target + " Heroes.Levitation.Speed.Base");
					entity.server.runCommandSilent("execute as " + username + " at @s if score .IntuitiveHold_1 Heroes.Intuitive.Study > @s Heroes.Levitation.Speed.Intuitive run scoreboard players operation @s Heroes.Levitation.Speed.Intuitive = .IntuitiveHold_1 Heroes.Intuitive.Study");
					entity.server.runCommandSilent("scoreboard players reset .IntuitiveHold_1 Heroes.Intuitive.Study");
					}
					if (power == 'Bone_Protrusion') {
					entity.server.runCommandSilent("execute as " + username + " at @s run scoreboard players operation .IntuitiveHold_1 Heroes.Intuitive.Study = " + username_target + " Heroes.Bone.Var.Base");
					entity.server.runCommandSilent("execute as " + username + " at @s if score .IntuitiveHold_1 Heroes.Intuitive.Study > @s Heroes.Bone.Var.Intuitive run scoreboard players operation @s Heroes.Bone.Var.Intuitive = .IntuitiveHold_1 Heroes.Intuitive.Study");
					entity.server.runCommandSilent("scoreboard players reset .IntuitiveHold_1 Heroes.Intuitive.Study");
									}
									break;
									}
								}
							}
					}
						entity.persistentData[username + "_" + username_target + "_Bond"] = 0
					}
				}
					
					
				if (bond < 36000) {
					if (power_amount >= 1) {
					entity.persistentData[username + "_" + username_target + "_Bond"] = bond + 1
					}
						
							}
			}
	  
					}
                }
            });
    });