im making a roblox obby game were you are jumping on a piano and each time you land on a white key it plays a noise and glows and every time you go on the black key it plays a different noise but they die can you code it for me
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure! Here's a simple Roblox Lua script that you can use to create the behavior you're describing for your piano obby game:
🔹 Features:
When a player touches a white key, it plays a sound, glows, and continues.
When a player touches a black key, it plays a different sound and kills the player.
🧱 Step-by-step Setup in Roblox Studio:
1. Create the Piano Keys
Create parts for each piano key (e.g., WhiteKey and BlackKey) in your obby.
Group them under something like a Piano folder for organization.
Make sure they are not anchored and have CanCollide = true.
2. Add Sounds
Insert two sounds into Workspace or a folder:
One called WhiteKeySound (for white keys).
One called BlackKeySound (for black keys).
You can upload your own piano notes or use free Roblox sounds from the toolbox.
📜 Script: Place this in ServerScriptService
lua
-- Configuration
local WHITE_KEY_COLOR = Color3.new(1, 1, 1) -- White color
local GLOW_COLOR = Color3.new(1, 0, 0) -- Red glow for example
-- Function for white key behavior
local function onWhiteKeyTouched(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then return end
local key = hit.Parent
local sound = key:FindFirstChild("WhiteKeySound")
if sound then
sound:Play()
-- Optional Glow Effect
local originalColor = key.BrickColor
key.BrickColor = BrickColor.new(GLOW_COLOR)
wait(0.2)
key.BrickColor = originalColor
end
end
-- Function for black key behavior
local function onBlackKeyTouched(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then return end
local key = hit.Parent
local sound = key:FindFirstChild("BlackKeySound")
if sound then
sound:Play()
end
humanoid.Health = 0 -- Kill the player
end
-- Connect the functions to all keys
for _, key in pairs(workspace.Piano:GetChildren()) do
if key:IsA("BasePart") then
if key.Name == "WhiteKey" then
key.Touched:Connect(onWhiteKeyTouched)
elseif key.Name == "BlackKey" then
key.Touched:Connect(onBlackKeyTouched)
end
end
end
🛠️ Optional Improvements
Add more effects like particles or animations when hitting a white key.
Use different sounds per white key to make real melodies.
Add a respawn point or checkpoint system.
Play a specific song by timing key presses.
✅ Final Notes
Make sure:
Each key has a proper name (WhiteKey, BlackKey).
Each key has the correct sound inserted as a child.
The keys are inside a folder named Piano in Workspace.
Let me know if you want to make each white key play a different note (like C, D, E, etc.) or add visual effects like sparks on death!