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

Function won't call?

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

0

Is there any error in the output?

0

Is it in a LocalScript?

0

It is in a local script and does not have any error. :(

0

How does it not error when it's missing an end to line 6 and line 42 tries to index a nil value?

2 answers

✓ Accepted answer

You're calling the function CastSpell with no arguments when it has a spell parameter. Inside that function, spell.A1:Play() should error because spell is not defined.

On line 72, the connection to the function CastSpell needs to pass whatever necessary argument needs to be passed to that function.

mouse.Button1Down:connect(function()
	CaseSpell(argument)
end)

Also, the function on line 6 does not have an end.

1 comment

0

*You're welcome

I didn't look through your code because it wasn't tabbed correctly. Please tab your code in the future so it is easy for people to read.

You were missing an "end". You would have caught that if you had tabbed correctly.

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:Destroy()
			end
		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:Destroy()
		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)

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