This part of the script is supposed to make the previously created 5 parts heal what they touch, but Output returns: Attempt to index field 'Touched'(a nil value)
wait()
local h = game.Workspace
local durt = {h.durt1,h.durt2,h.durt3,h.durt4,h.durt5}
local function onTouch(hit)
if hit.Parent.FindFirstChild("Humanoid") then
local hp = hit.Parent.Character.Humanoid.Health
hp = hp+hp+durt.Size*5
end
end
durt.Touched:connect(onTouch)
full code:
wait()
player = game.Players.LocalPlayer
Torso = player.Character.Torso
human = Torso.Parent.Humanoid
game:GetService("UserInputService").InputBegan:connect(function(inputObject,gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
local pos = Torso.Position
local q,e = {pos.X,pos.Z}
local w = (pos.Y + 10)
local anim = Instance.new("Animation",human)
anim.AnimationId = "https://www.roblox.com/Healing-Move-item?id=439811959"
local animtrack = human:LoadAnimation(anim)
animtrack:Play()
wait(2)
local bp = Instance.new("BodyPosition", Torso)
bp.MaxForce = Vector3.new(0,10000,0)
bp.P = 10000
bp.Position = Vector3.new(q,w,e)
Torso.Parent.Humanoid.WalkSpeed = 0
wait(2)
math.randomseed(tick())
for i = 1,5 do
local num = i
i = Instance.new("Part", workspace)
i.Name = "durt" .. num
i.Size = Vector3.new(math.random(4),math.random(4),math.random(4))
local m = math.random(-20,20)
local a = pos.x+m
local m = math.random(-20,20)
local b = pos.y+m
local m = math.random(-20,20)
local c = pos.z+m
i.Transparency = 1
i.Position = Vector3.new(a,b,c)
i.CanCollide = false
i.Shape = 0
i.BrickColor = BrickColor.new(1020)
i.TopSurface = 0
i.RightSurface = 0
i.LeftSurface = 0
i.FrontSurface = 0
i.BottomSurface = 0
i.BackSurface = 0
local k = Instance.new("BodyPosition", i)
k.MaxForce = Vector3.new(50000,50000,50000)
k.P = 100
k.D = 100
w = w+.5
k.Position = Vector3.new(pos.x,w,pos.z)
end
wait()
local h = game.Workspace
local durt = {h.durt1,h.durt2,h.durt3,h.durt4,h.durt5}
local function onTouch(hit)
if hit.Parent.FindFirstChild("Humanoid") then
local hp = hit.Parent.Character.Humanoid.Health
hp = hp+hp+durt.Size*5
end
end
durt.Touched:connect(onTouch)
local h = game.Workspace
local durt = {h.durt1,h.durt2,h.durt3,h.durt4,h.durt5}
for j = 1,0,-.05 do
wait(.1)
h.durt1.Transparency = j
h.durt2.Transparency = j
h.durt3.Transparency = j
h.durt4.Transparency = j
h.durt5.Transparency = j
end
end
end)
