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

This script sends a notification through juju''s menu when a player joins or leaves the server.

local juju = juju -- This is not neccessary.
    local create_connection = juju["create_connection"]
    local create_notification = juju["create_notification"]
local players_service = cloneref(game:GetService("Players"))
local player_image_data = base64_decode("")
    
local do_join_notification = function(player)
    create_notification(player["Name"].." has joined the server!", 2)
end

local do_leave_notification = function(player)
    create_notification(player["Name"].." has left the server!", 2)
end

-- >> ui toggle

local example_toggle = juju["create_element"]({
    ["name"] = "player join logs"
}, {
    ["toggle"] = {
        flag = "example",
        default = false
    }
})

-- >> core

local example_connection2 = nil
local example_connection = nil

create_connection(example_toggle["on_toggle_change"], function(bool)
    if example_connection then
        example_connection:Disconnect()
        example_connection = nil
    end
    
    if example_connection2 then
        example_connection2:Disconnect()
        example_connection2 = nil
    end

    if bool then
        example_connection = create_connection(players_service["PlayerAdded"], do_join_notification)
        example_connection2 = create_connection(players_service["PlayerRemoving"], do_leave_notification)
    end
end)

-- >> clean up

juju["on_unload"](function()
    print("bye bye :(")
    -- Notice we don't need to disconnect our connections above since we 
    -- used juju's built in create_connection function!
end)

PreviousNecessitiesNextExample Script 2

Last updated 3 months ago