Proximity Egg Pickup Module

A server-authoritative Roblox Studio helper that attaches a ProximityPrompt to your own egg part and delegates pickup validation.

Roblox Studio ModuleScript

What this script does

Create a visible prompt with line-of-sight and distance limits while leaving ownership, capacity, and reward checks in your callback.

Best for
Original collectible, egg, item, and interaction prototypes.
Language
Luau
Version
1.0.0
Validation
Luau checked · Studio integration required
Luau checked · Studio integration required

Official Luau 0.735 parsing and static analysis pass with Roblox host types stubbed. Test the actual Instance, service, or event integration in a separate Studio place before production use.

Included behavior

  • Built-in ProximityPrompt setup
  • Single busy state per prompt
  • Callback decides whether the item was consumed

Install in the stated runtime

  1. 1
    Create a ModuleScript named EggPickup.
  2. 2
    Paste the complete source and require it from a server or test Script in your own experience.
  3. 3
    Bind on the server and make the callback recheck distance, capacity, ownership, and item state before returning true.

Minimal usage example

local EggPickup = require(script.Parent.EggPickup)
EggPickup.bind(workspace.DemoEgg, function(player, eggPart)
	print(player.Name, "picked", eggPart.Name)
	eggPart:Destroy()
	return true
end)

Example inputs and result

Supply
Your own Egg part and an interaction callback receiving player and Egg.
Expect
bind connects the interaction; your callback decides whether to award or remove the Egg.

These notes explain the example above. Read the complete source for every exported function and edge case before integrating it.

Complete source

No hidden import, minified block, or shortened loader.

--!strict
-- MIT License. Binds a server-authoritative ProximityPrompt to your own egg part.

local EggPickup = {}

function EggPickup.bind(part: BasePart, onPickup: (Player, BasePart) -> boolean, cooldownSeconds: number?)
	local prompt = part:FindFirstChildOfClass("ProximityPrompt") or Instance.new("ProximityPrompt")
	prompt.ActionText = "Pick up"
	prompt.ObjectText = part.Name
	prompt.MaxActivationDistance = 10
	prompt.RequiresLineOfSight = true
	prompt.Parent = part
	local busy = false
	local connection = prompt.Triggered:Connect(function(player)
		if busy or not player.Parent then return end
		busy = true
		prompt.Enabled = false
		local consumed = onPickup(player, part)
		if not consumed and part.Parent then
			task.delay(math.max(0, cooldownSeconds or 0.5), function()
				busy = false
				prompt.Enabled = true
			end)
		end
	end)
	return connection
end

return table.freeze(EggPickup)
SHA-2564a9b0cc048242d851efa966de37f8b4c0d2fb2ce4287cc8682319c8e2b034d18

Outside this script’s scope

  • Pick up items for the player
  • Reach into another experience

Found a problem or a better approach?

Tell us what failed, what you expected, and whether the issue happened in the Luau CLI or Roblox Studio. Suggestions for clearer types, safer server checks, or a more useful API are welcome.

Do not submit credentials, private project files, or account data.