Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

It works, thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.