so i want to make a roblox obby game where you have to carry an egg through the obby and you try not to crack the egg. if you crack the egg you die and have to go back to your recent checkpoint. to crack the egg, the players egg bumps into a part and it cracks. another way they can crack the egg is by sprinting for too long and the egg falls. the player gets a sprint for lets say 3 seconds for now and if they go over 3 seconds, the egg falls. i want to start off with the picking up the egg to start the obby. how can i make it so the player presses E to pick up the egg? by the way the egg is not a real item its just a model i made called EggModel.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's how to create the egg pickup system for your obby:
Step 1: Set up the EggModel
First, make sure your EggModel has a PrimaryPart set (usually the main egg part). In Roblox Studio, select your EggModel and set the PrimaryPart property in the Properties window.
Step 2: Create the pickup script
Put this ServerScript inside your EggModel:
lua
local EggModel = script.Parent
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Create RemoteEvents for client-server communication
local pickupEggEvent = Instance.new("RemoteEvent")
pickupEggEvent.Name = "PickupEggEvent"
pickupEggEvent.Parent = ReplicatedStorage
local proximityPrompt = Instance.new("ProximityPrompt")
proximityPrompt.ActionText = "Pick up Egg"
proximityPrompt.KeyboardKeyCode = Enum.KeyCode.E
proximityPrompt.HoldDuration = 0
proximityPrompt.MaxActivationDistance = 10
proximityPrompt.Parent = EggModel.PrimaryPart
proximityPrompt.Triggered:Connect(function(player)
-- Weld egg to player's character
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") then
local weld = Instance.new("WeldConstraint")
weld.Part0 = character.HumanoidRootPart
weld.Part1 = EggModel.PrimaryPart
weld.Parent = EggModel.PrimaryPart
-- Position egg in front of player
EggModel:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3))
-- Disable the prompt so others can't pick it up
proximityPrompt.Enabled = false
-- Store reference that player has egg
player:SetAttribute("HasEgg", true)
print(player.Name .. " picked up the egg!")
end
end)
Step 3: Make the egg follow the player smoothly
Add this LocalScript inside StarterPlayerScripts:
lua
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local connection
local function updateEggPosition()
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") and player:GetAttribute("HasEgg") then
local egg = workspace:FindFirstChild("EggModel")
if egg and egg.PrimaryPart then
-- Smoothly move egg to follow player
local targetCFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, -1, -2)
egg:SetPrimaryPartCFrame(egg.PrimaryPart.CFrame:Lerp(targetCFrame, 0.1))
end
end
end
-- Start updating when player spawns
player.CharacterAdded:Connect(function()
if connection then connection:Disconnect() end
wait(1) -- Wait for character to fully load
connection = RunService.Heartbeat:Connect(updateEggPosition)
end)
This setup gives you:
E key pickup using ProximityPrompt (shows UI prompt when near)
Egg follows player smoothly in front of them
Only one player can pick up the egg at a time
Attribute tracking so you know who has the egg
Next, you'll want to add the sprint timer and collision detection. Want me to show you how to implement those systems?