$execute if entity @e[limit=1,nbt={UUID:$(to_leash)}] run tag @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=!Happy_Ghast.Found_Leashable_Entity] add Happy_Ghast.Found_Leashable_Entity

$execute if items entity @s container.* minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] unless data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] ",{selector:"@e[limit=1,nbt={UUID:$(to_leash)}]"}," §aas been leashed by the Happy Ghast."]
$execute if items entity @s container.* minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] if data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] ",{selector:"@e[limit=1,nbt={UUID:$(to_leash)}]"}," §aas been leashed by the Happy Ghast named \"",{selector:"@e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}]"},"§a\"."]
$execute if items entity @s container.* minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run playsound minecraft:block.note_block.banjo master @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 2
$execute if items entity @s weapon.offhand minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] unless data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] ",{selector:"@e[limit=1,nbt={UUID:$(to_leash)}]"}," §aas been leashed by the Happy Ghast."]
$execute if items entity @s weapon.offhand minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] if data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] ",{selector:"@e[limit=1,nbt={UUID:$(to_leash)}]"}," §aas been leashed by the Happy Ghast named \"",{selector:"@e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}]"},"§a\"."]
$execute if items entity @s weapon.offhand minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run playsound minecraft:block.note_block.banjo master @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~

$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=!Happy_Ghast.Found_Leashable_Entity] unless data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] §cThere is no entity to leash at the Happy Ghast."
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=!Happy_Ghast.Found_Leashable_Entity] if data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] §cThere is no entity to leash at the Happy Ghast named \"",{selector:"@e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}]"},"§c\"."]
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=!Happy_Ghast.Found_Leashable_Entity] run playsound minecraft:block.note_block.banjo master @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 0.5
$execute unless items entity @s container.* minecraft:lead unless items entity @s weapon.offhand minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] §cYou don\'t have Lead in your inventory."
$execute unless items entity @s container.* minecraft:lead unless items entity @s weapon.offhand minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run playsound minecraft:block.note_block.banjo master @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 0.5

$execute if items entity @s container.* minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run data modify entity @e[limit=1,nbt={UUID:$(to_leash)}] leash.UUID set value $(Selected)
$execute if items entity @s weapon.offhand minecraft:lead if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run data modify entity @e[limit=1,nbt={UUID:$(to_leash)}] leash.UUID set value $(Selected)
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] run clear @s[gamemode=!creative,gamemode=!spectator] minecraft:lead 1

$tag @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Found_Leashable_Entity] remove Happy_Ghast.Found_Leashable_Entity

$execute unless entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..6.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§7[§r§6§lBetter §r§7§lHappy Ghast§r§7] §cNo selected Happy Ghast as been found in a distance of 6.5 blocks."
$execute unless entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..6.5] run playsound block.note_block.pling master @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 0.5