Adventure Game Opening Chests with Event Schedule Script

Adventure Game Opening Chests


  • Open a chest and observe the chest opening.
  • Display the contents.
  • Hide the chest after x time.
  • Pick up the contents.

Starter: Adventure Game

  • this starter game has the basics required for this tutorial.

Additional Packages

  • Door Package (Official Crayta Package)


This tutorial will use the pickupSpawnerScript on a locator to control the chest visibility using show and hide functions. The doorScript will be used to control the opening and closing of the chest. The eventScheduleScript will be used to control the above scripts and timing.

Building the Chest and Apple

  • place a locator in the world
  • place a chest on the locator
  • place the resourceSpawner template aka Apple on the chest
World Tree Editor View

Adding Scripts

For ease of visibility, script folders will be used to identify script placement and access. Add the following script folders to each entity, and associated scripts with settings:


  • .locator pickupSpawner
    • pickupSpawnerScript
      • respawning = false
      • useSelfAsTemplate = false
      • showOnInit = true


  • use of .locator name to show it at the top.
  • easier to see with child objects.


  • largeChest door
    • doorScript
      • defaults i.e. closed

This is an Event Container or Array of Events with a delay or timer beteen sets.

  • largeChest eventSchedule
  • eventScheduleScript
    • eventSet 1
      • largeChest door / doorScript / SetOpening
      • resourceSpawner1 / pickupSpawnerScript / ShowPickup
    • eventSet 2
      • largeChest door / doorScript / SetClosed
      • .locator pickupSpawner / pickupSpawnerScript / HidePickup
    • WaitTime = 1
      • wait 1 seconds between events
      • adjust as desired
Event Schedule Script
local EventScheduleScript = {}

EventScheduleScript.Properties = {
	{ name = "eventSet", type = "event", container = "array", tooltip = "do set 1 and then wait, etc.", },
	{ name = "waitTime", type = "number", min = 0, tooltip = "time to wait between events", },

function EventScheduleScript:Init()

function EventScheduleScript:DoEvents(player)

	local events = self:ReturnTable(
		for _, event in pairs (events) do

function EventScheduleScript:ReturnTable(arrayName)

    local tempTable = {}
    for i=1, #arrayName do
        table.insert(tempTable, arrayName[i])
    return tempTable

return EventScheduleScript

  • largeChest interact
    • interactMsgScript
      • InteractMsg = Open Chest
local InteractMsgScript = {}

InteractMsgScript.Properties = {
	{ name = "interactMsg", type = "text", },

function InteractMsgScript:Init()

function InteractMsgScript:GetInteractPrompt(prompts)

	prompts.interact =

return InteractMsgScript

Resouce Spawner

  • pickupSpawnerScript
    • respawning = false
      • showOnInit = false

Setting Things in Motion

With the above logic in place, preview the game. The chest does not open when interacting with it. One additional piece is required; setting up OnInteract on the chest itself. Drag the script folder largeChest eventSchedule onto the OnInteract Entity Field, and select the function DoEvents.


  • On Interact
    • largeChest eventSchedule / eventScheduleScript / DoEvents

Supporting Images

pickupSpawnerScript largeChest OnInteract



  • the chest should appear in the game
  • click on the chest to see it open
  • the apple is in the chest
  • the chest will hide in 1 seconds
  • the apple will remain

Respawning chests

  • not shown in this tutorial

There are multiple ways of setting things in motion with an event schedule.

This game is published and remixable for the curious and/or brave.