This is located inside a tool in the starterpack. When the tool is equipped and clicked it should perform a function that I made. Why won't this run? Thanks -Doctorbenny2011
local wand = script.Parent
local stick = wand.Handle
local inc = script.Name
local owner, connect
function SpellAffectAvadaKedavra(hit,spell)
if (not hit.CanCollide) and (hit.Parent:findFirstChild("Humanoid") == nil) then return end
local hum = hit.Parent:findFirstChild("Humanoid")
if (hum) then
wait(.5)
spell.A2:Play()
hum.Health = 0
if hit.Name == "Handle" then
if hit.Parent.Parent == game.Workspace then
local i = Instance.new("BodyPosition")
i.position = wand.Parent.Torso.Position
i.Parent = hit
wait(3)
i.Parent = nil
spell:Remove()
end end end
function Setup()
for i,p in pairs(game.Players:children()) do
if (p.Character == wand.Parent) then
print("Found owner of wand!")
if (connect ~= nil) then connect:disconnect() end
owner = p
end
end
end
local s1 = script.Parent.Handle.A1:Clone()
local s2 = script.Parent.Handle.A2:Clone()
function CastSpell(spell)
if game.Players.LocalPlayer.PlayerGui.Spell.Spell.Text.Value == "Spell : Avada Kedavra" then
s1.Parent = spell
s2.Parent = spell
wand.Activated:wait()
spell.A1:Play()
local p = Instance.new("Part")
p.formFactor = "Symmetric"
p.Shape = "Ball"
p.Size = Vector3.new(1,1,1)
p.TopSurface = "Smooth"
p.BottomSurface = "Smooth"
p.Transparency = 0.5
p.BrickColor = script.AvadaKedavraColor.Value
local sparx = Instance.new("Sparkles")
sparx.SparkleColor = script.AvadaKedavraSparksColor.Value
sparx.Enabled = script.HasSparkles.Value
sparx.Parent = p
coroutine.resume(coroutine.create(function()
wait(10)
p:Remove()
end))
local bv = Instance.new("BodyVelocity")
p.Parent = workspace
p.Name = "MagicSpell"
p.CFrame = stick.CFrame * CFrame.new(0,1.5,0)
bv.Parent = p
bv.velocity = ((owner.Character.Humanoid.TargetPoint - p.Position).unit) * 200
p.Touched:connect(function(part)
SpellAffectAvadaKedavra(part,p)
end)
end
end
wand.Equipped:connect(Setup)
script.Parent.Equipped:connect(function(mouse)
mouse.Button1Down:connect(CastSpell)
end)

4 comments
Is there any error in the output?
Is it in a LocalScript?
It is in a local script and does not have any error. :(
How does it not error when it's missing an end to line 6 and line 42 tries to index a nil value?