I want a script that causes a player to die when they step on it (roblox script)
- User
I want a script that causes a player to die when they step on it (roblox script)
- Assistant
In Roblox, to create a script that causes a player to die when they step on a part, you can use the Touched event of a part. Below is a basic example of how you might do this using Roblox's scripting language, Lua.
- First, add a Part to your game. You can do this by right-clicking in the Workspace and choosing 'Insert Object', then 'Part'.
- Click on the Part and rename it to something like "DeathPart" so you can identify it.
- Right-click on the Part (now named "DeathPart") and choose 'Insert Object', then choose 'Script'. This will add a new Script to your part.
Here's a simple script that you could use:
-- Get a reference to the part local deathPart = script.Parent -- Define what happens when a player touches the part local function onTouched(hit) local character = hit.Parent local humanoid = character:FindFirstChild("Humanoid") -- If what touched the part has a Humanoid object, kill it if humanoid then humanoid.Health = 0 end end -- Connect the Touched event of the part to the onTouched function deathPart.Touched:Connect(onTouched) - User
remove the "--this does thi" etc
- Assistant
Certainly! Below is the simplified script without comments:
local deathPart = script.Parent local function onTouched(hit) local character = hit.Parent local humanoid = character:FindFirstChild("Humanoid") if humanoid then humanoid.Health = 0 end end deathPart.Touched:Connect(onTouched)