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

How do i insert a script into a part inside a script?

Asked by 6 years ago
Edited 6 years ago

So basically I'm trying to make a script for VSB or Void Script Builder and I'm trying to figure out how to do it

The script is supposed to spawn a part with a script inside it to kill any player it touched.

I'm going to put this into separate scripts

Script 1: Trap = Instance.new("Part", workspace)

Script 2: Trap.Name = "KillPart"

Script 3: https://paste.ee/r/VPcde

Script 3 was a link cause inline code never worked with it.

0
There's a thing called a 'code block" which you can use to put multiple lines of code into your question. :P User#20279 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You don't need separate scripts to do what you want. You can just do it in one script. You also can just parent the script itself to the part with one line of code.

Here's what I did to your scripts :

local KillPart = Instance.new('Part') -- Combined script 1 into 3. Also parent it in a seperate line of code
KillPart.Position = Vector3.new(0, 0, 0) -- Creating part puts it in the center of the place. Change the values if you want it somewhere else.
KillPart.Parent = workspace
KillPart.Name = "Trap" -- Combined script 2 into 3
script.Parent = KillPart -- Parents script into part

local function onPartTouch(otherPart)
    local partParent = otherPart.Parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then -- Removed () as they are not neccessary
        humanoid.Health = 0
    end
end

KillPart.Touched:Connect(onPartTouch)

As you can see, I created the part and parented the script into it. I also combined all your scripts into one script. Note that your part will spawn at the center of the place unless you change its coordinates.

Hoped this helped!

Ad

Answer this question