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

How to make part break when a specific object touches it?(Misake in first)

Asked by 6 years ago

This glass breaking script only breaks when any object touches it, because it is onTouch. How ever how would i make it were a specific object touches it that is located in the workspace, like the baseplate?

local Glass = script.Parent
local DecalBack = Glass["BackD"]
local DecalFront = Glass["FrontD"]
local TextureId = Glass.Texture
local broken = false

function onTouched()
if broken == false then
broken = true
DecalBack.Texture = TextureId.Value
DecalFront.Texture = TextureId.Value
elseif broken == true then
local g1 = Instance.new("Part")
g1.formFactor = "Plate"
g1.Size = Vector3.new(1, 0.2, 1)
g1.Parent = Glass.Parent
g1.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g1.BrickColor = Glass.BrickColor
local g2 = Instance.new("Part")
g2.formFactor = "Plate"
g2.Size = Vector3.new(1, 0.2, 1)
g2.Parent = Glass.Parent
g2.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g2.BrickColor = Glass.BrickColor
local g3 = Instance.new("Part")
g3.formFactor = "Plate"
g3.Size = Vector3.new(1, 0.2, 1)
g3.Parent = Glass.Parent
g3.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g3.BrickColor = Glass.BrickColor
local g4 = Instance.new("Part")
g4.formFactor = "Plate"
g4.Size = Vector3.new(1, 0.2, 1)
g4.Parent = Glass.Parent
g4.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g4.BrickColor = Glass.BrickColor
local g5 = Instance.new("Part")
g5.formFactor = "Plate"
g5.Size = Vector3.new(1, 0.2, 1)
g5.Parent = Glass.Parent
g5.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g5.BrickColor = Glass.BrickColor
local g6 = Instance.new("Part")
g6.formFactor = "Plate"
g6.Size = Vector3.new(1, 0.2, 1)
g6.Parent = Glass.Parent
g6.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g6.BrickColor = Glass.BrickColor
local g7 = Instance.new("Part")
g7.formFactor = "Plate"
g7.Size = Vector3.new(1, 0.2, 1)
g7.Parent = Glass.Parent
g7.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g7.BrickColor = Glass.BrickColor
local g8 = Instance.new("Part")
g8.formFactor = "Plate"
g8.Size = Vector3.new(1, 0.2, 1)
g8.Parent = Glass.Parent
g8.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g8.BrickColor = Glass.BrickColor
local g9 = Instance.new("Part")
g9.formFactor = "Plate"
g9.Size = Vector3.new(1, 0.2, 1)
g9.Parent = Glass.Parent
g9.Position = Glass.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
g9.BrickColor = Glass.BrickColor

Glass:remove()

wait(10)
g1:remove()
g2:remove()
g3:remove()
g4:remove()
g5:remove()
g6:remove()
g7:remove()
g8:remove()
g9:remove()
end
end

Glass.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by
zblox164 531 Moderation Voter
6 years ago

There are a few ways you could do this. You would need a parameter on your function such as "Hit" because you need to check what hits the object.

  1. You could put an if statement that checks the class name . Example:
if hit.ClassName == "Class" then
    -- What you want to happen
end
  1. You could again use an if statement but instead of using Class Name you could use a function called IsA(). Example:
if hit:IsA("Class") then
    print("Working)
end
  1. Check the name of the object that touches the part. Example:
if hit.Name == "NameHere" then
    print("Hello World!"
end
  1. You could combine a few of the above and create a simple system that checks the class, and name. Here's an example of the most efficient way I found to do this:
if hit:IsA("Class") or hit.Name == "NameHere" then
    print("Hope this works for you!"
end

If that does not work then I don't know. Anyway hope this helps you achieve your goal!

0
Ok thank you ill try it to see if ut works. Carforlife1 59 — 6y
Ad

Answer this question