Solved Making skript choose a random block on the players y-co-ordinate that is air & in a radius of 10

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!


    You can always check out skUnity Downloads for downloads and any other information about Skript!

Not open for further replies.


Jul 12, 2017
i have been trying to get this skript code working as intented for a while now

it is meant to replace a random block in a radius of 10 of the player with a chest but only on the same y-level of the player, so if it fails to choose an air block on the same y-level as the player it should try again, but i cannot get this to work

function chestSummon(block: location):
    set block at {_block} to chest
    #Here is where you add the items this is just an example
    add 1 diamond sword to block at {_block}'s inventory
    #Here is where you check if the chest has items
    wait 1 tick
    while block at {_block} is a chest:
        if items in block at {_block}'s inventory isn't set:
            set block at {_block} to air
        wait 1 tick

function addBlocks(player: player, radius: integer):
    #here you get a random block
    loop blocks in radius {_radius} around {_player}:
        loop-block is air
        set {_1} to "%loop-block's y-coordinate%"
        set {_loc1::*} to {_1} split at "."
        set {_2} to "%{_player}'s y-coordinate%"
        set {_loc2::*} to {_2} split at "."
        {_loc1::1} = {_loc2::1}
        add loop-block to {_blocks::*}
    if {_blocks::*} is set:
        set {_block} to a random block out of {_blocks::*}
        chestSummon({_block}'s location)
        wait 1 tick
        addBlocks({_player}, {_radius})

the 1st part works as intended the chest spawns with the test item in it, but the second part will only spawn the chest at the players feet and will also not detect if it is air so if your standing on a slab it replaces the slab, could i get some help fixing this please
You can try broadcasting variables to see what exactly isn't working
could it be how i am calling the function?
on rightclick:
    if player is holding torch named "&r&lSimple Flare &6(Right-Click)" with lore "&7Right-click to summon a Simple Drop Package":
        remove 1 torch named "&r&lSimple Flare &6(Right-Click)" with lore "&7Right-click to summon a Simple Drop Package" from players
with skyrayfall you can:
on store:
    cancel event
however im not sure how you could do this for a specific chest becuase theres no event-block or anything to get the location of the chest
[doublepost=1500476506,1500476375][/doublepost]i guess the next best thing would to make a region around the chest and check if the player is in the region
Not open for further replies.