juju scripting documentation
  • Scripting Documentation
  • Creating a script
    • Necessities
      • Example Script
      • Example Script 2
      • Example Script 3
  • Documentation
    • Elements
      • Element Properties
      • Element API
    • Utility Functions
  • Da Hood
    • Signals
    • Functions
Powered by GitBook
On this page
  1. Creating a script
  2. Necessities

Example Script 3

This script automatically purchases and eats lettuce until the local player is fully skinny.

-- >> variables

local juju = juju
    local create_connection = juju["create_connection"]
    local is_purchasing = juju["is_purchasing"]
    local purchase_item = juju["purchase_item"]
local players_service = cloneref(game:GetService("Players"))
    local local_player = players_service["LocalPlayer"]
    local local_character = local_player["Character"]
    local local_hrp = local_character and local_character:FindFirstChild("HumanoidRootPart") or nil

local on_local_character_loaded = juju["get_signal"]("on_local_character_loaded")
local find_first_child = workspace["FindFirstChild"]
local wait_for_child = workspace["WaitForChild"]
local heartbeat = cloneref(game:GetService("RunService"))["Heartbeat"]

-- >> get data 

local data_folder = wait_for_child(local_player, "DataFolder", 9e9)
    local information_folder = wait_for_child(data_folder, "Information", 9e9)
    local muscle_information = wait_for_child(information_folder, "MuscleInformation", 1) or {["Value"] = -150}
    
if not muscle_information then
    local connection = nil; connection = create_connection(information_folder["ChildAdded"], function(child)
        if child["Name"] == "MuscleInformation" then
            muscle_information = child
            connection:Disconnect()
        end
    end)
end

-- >> ui toggle

local toggle = juju["create_element"]({
    ["name"] = "auto skinny"
}, {
    ["toggle"] = {
        flag = "auto_skinny",
        default = false
    }
})

-- >> core

local character_added_connection = nil
local auto_skinny_connection = nil

local update_character_information = function()
    local_character = local_player["Character"]
    local_hrp = wait_for_child(local_character, "HumanoidRootPart", 9e9)
end

local do_auto_skinny = function()
    if not local_character or not local_hrp then
        return
    end

    local lettuce = find_first_child(local_player["Backpack"], "[Lettuce]") -- > not setting up caching for an example script f off

    if lettuce then
        lettuce["Parent"] = local_character
        lettuce:Activate()
        return
    end

    if tonumber(muscle_information["Value"]) > -15000 and not is_purchasing() then
        purchase_item("lettuce")
    end
end

create_connection(toggle["on_toggle_change"], function(value)
    if character_added_connection then
        character_added_connection:Disconnect()
        character_added_connection = nil
    end

    if auto_skinny_connection then
        auto_skinny_connection:Disconnect()
        auto_skinny_connection = nil
    end
    
    if value then
        character_added_connection = create_connection(on_local_character_loaded, update_character_information)
        auto_skinny_connection = create_connection(heartbeat, do_auto_skinny)
    end
end)

-- >> clean up

juju["on_unload"](function()

end)
PreviousExample Script 2NextElements

Last updated 3 months ago