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

When I summon a part using Instance.new I can't add other scripts next to the Instance.new code?

Asked by 4 years ago
part = Instance.new("Part")
part.Parent = game.Workspace

Instance.new("Part")
part.Anchored = false
part.BrickColor = BrickColor.new("Dark green")
part.Position = Vector3.new(0,100,0)
part.Size = Vector3.new(0.5,3,0.5)

local part = script.Parent

local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        humanoid.Health = 0
    end
end
part.Touched:Connect(onPartTouch)

If I paste everythin from local part = script.Parent and so on into a normal part it will work but won't work with Instance.new? Is it possible to fix that?

1 answer

Log in to vote
0
Answered by
SirGamezy 186
4 years ago

If you want the script's parent to be the new part, then try this:

local part = Instance.new("Part", workspace)

part.Anchored = false
part.BrickColor = BrickColor.new("Dark green")
part.Position = Vector3.new(0, 100, 0)
part.Size = Vector3.new(0.5, 3, 0.5)

script.Parent = part

local function onPartTouch(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid.Health = 0
    end
end)

part.Touched:Connect(onPartTouch)
0
It works, thank you! ScrewedPower 33 — 4y
Ad

Answer this question