Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make an object that is falling damge me when I touch it?

Asked by 4 years ago
Edited 4 years ago

I am new at ROBLOX scripting and have made the following code/script to make an object spawn infinitely.

while true do

wait(2)

hello = Instance.new("Part")

hello.Position = Vector3.new(0,22,0)

hello.Anchored = false

hello.CanCollide = false

hello.BrickColor = BrickColor.new("Baby blue")

hello.Parent = game.Workspace

end

However, I want to make it so that when the person hits the object they take damage and eventually die. I have tried looking up touch events that make this happen but do not seem to work.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
"use code blocks"

Anyways, I'm also quite new to coding. I'm certainly no expert (or even good) at scripting but here's how you fix it I think:

while true do
    local newPart = Instance.new("Part", game.Workspace)
    newPart.Name = "Part"
    newPart.Anchored = false
    newPart.Position = CFrame.new(0, 60, 0)
    newPart.BrickColor = BrickColor.new("Baby blue")
    wait(2)
end

tl;dr: Put the wait at the end

Ad
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

I've optimized your scripted

while true do
wait(2)
hello = Instance.new("Part")
hello.Position = Vector3.new(0,22,0)
hello.Anchored = false
hello.CanCollide = false
hello.BrickColor = BrickColor.new("Baby blue")
hello.Parent = game.Workspace
script.Parent.Touched:Connect(function(hit) 
if hit.Parent:FindFirstChild( "Humanoid") then -- if whatever hits has a humanoid then fire an event
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -25 -- The amount of damage change this to your preference.

end
0
Unfortunately, JeeseSong the additional script you have given me does not work as the block does not seem to take damage when it falls on the ground. doctorstrange8383 0 — 4y

Answer this question