Inserting a part with a script inside of it (and the script having text) using Instance.new

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a part that has a kill script inside of it using a script (using instance.new)
  2. What is the issue? Include screenshots / videos if possible!
    I have decided to take matters into my own hands and watch AlvinBlox in order to learn how to script, and so far he’s mentioned instancing but it was just basic instancing, like the script at the bottom
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t tried anything so far
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Local part = Instance.new(“Part”)
part.Name = “MyAwesomePart”
part.BrickColor = BrickColor.new(“Really red”)
part.Anchored = true
part.Position = Vector3.new(0, 15, 0)
part.Transparency = 0.5
part.Reflectance = 0.6
part.CanCollide = false
part.Parent = workspace        

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Hello, try…

local damage = 10 -- Amount of damage per "waittime", 100 is instant death
local waittime = .1 -- The time to wait to damage

local part = Instance.new("Part")
part.Name = "MyAwesomePart"
part.BrickColor = BrickColor.new("Really red")
part.Anchored = true
part.Position = Vector3.new(0, 15, 0)
part.Transparency = 0.5
part.Reflectance = 0.6
part.CanCollide = false
part.Parent = workspace        

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local hum = hit.Parent.Humanoid
		wait(waittime)
		
		hum.Health = hum.Health - damage
	end
end)

I know this is not instancing a script, but it still works as a kill part.

1 Like

Game scripts can’t edit a scripts source, only plugins can.

2 Likes

First of all you can’t declare a local with a capital “L” in local. Secondly to achieve this all you need to do is have a template kill script which is cloned inside the part being made, for instance:

local killscript = workspace.KillScript --change this if necessary to reference your own killscript
local part = Instance.new("Part")
part.Parent = workspace
part.Name = "MyAwesomePart"
part.BrickColor = BrickColor.new("Really red")
part.Anchored = true
part.Position = Vector3.new(0, 15, 0)
part.Transparency = 0.5
part.Reflectance = 0.6
part.CanCollide = false 
local ksclone = killscript:Clone()
ksclone.Parent = part
2 Likes

Well I’m pretty new to scripting so I didnt know (I mean I started watching AlvinBlox like less than a week ago)

I was also wondering how I would make the part being inserted a sphere rather than a brick, because I need it to roll down a tunnel

also another thing: I’m guessing I could put all that in a fucntion and add a “wait” command between calling the function if I wanted a new boulder to spawn every so often?

part.Shape = Enum.PartType.Ball

1 Like

you can do

while true do
    --spawn script
    wait(5)
end
1 Like

is this true? could I actually just put a function and a “wait” command?

okay, thank you, I didnt see this at first lol

lol alright. thats just a basic loop