Hi, so im making a little gun that shoots particles and the block that those particles hit will turn into an emerald block for 4 seconds but its not working
function ems(p: player, length: number, dmg: number):
set {_x} to 0
set {_l} to 0
loop {_length} times: #loops as many times as long as the length from the function input
add 1 to {_x}
add 0.25 to {_l}
set {_rg%{_x}%} to location {_l} meters infront of {_p}
set {_rg%{_x}%} to location 1.25 meters above {_rg%{_x}%} #aligns with where player is looking better
# all of the locations are saved as soon as the function is called, effects such as particles can be applied afterwards.
set {_x} to 0
loop {_length} times:
add 1 to {_x}
show 3 light green dust at {_rg%{_x}%} #change color or particle type
show 1 green dust at {_rg%{_x}%} #change color or particle type
loop entities in radius 1 around {_rg%{_x}%}:
loop-entity is not {_p}
damage loop-entity by {_dmg}
stop #if you want your projectile to pierce entities, delete this line
loop blocks in radius 0.5 around {_rg%{_x}%}:
if loop-block is not glass or air or water:
set {block} to block at {_rg%{_x}%}
set {blockloc} to location of {block}
wait 1 tick
set block at {blockloc} to emerald block
wait 4 seconds
set block at {blockloc} to {block}
broadcast "%{blockloc}% %{block}%"
stop
on click:
if player's held item is emerald:
ems(player, 30, 0)