I have a script that i am very mad at, Now the error I am getting is Attempt to connect failed: Passed value is not a function: Line 42 - Reason for this is you can't equip an object in workspace, it has to be in your backpack, but i don't know how to have it wait to connect the functions

tool = script.Parent
function onTouched(hit)
	if hit.Name == "Left Leg" or hit.Name == "Right Leg" then
local name = tool.Parent.Name
print(name)
local character = workspace:FindFirstChild(name)
local player = game.Players:FindFirstChild(name)
wait(2)
print("executing")
local gun = player.Backpack.HLP:clone()
gun.Parent = character
gun.Name = "HipGun"
local weld = Instance.new("Weld")
weld.Parent = character.Torso
weld.Part0 = character.Torso
weld.Part1 = character.HipGun.Part1
weld.C0 = CFrame.new(-0.75,-0.4,0)*CFrame.fromEulerAnglesXYZ(0, math.pi*1.5, math.pi/2)
print("3")
function Equipped()
	print("4")
wait(0.001)
local animation = script.Slash
local plyr = script.Parent.Parent.Name
local char = workspace:FindFirstChild(plyr)
local anim = char.Humanoid:LoadAnimation(animation)
anim:Play()
print("5")
gun.Part1.Transparency = 1
gun.Part.Transparency = 1
end
print("6")
function unEquipped()
	print("7")
gun.Part1.Transparency = 0
gun.Part.Transparency = 0
print("8")
end
	end
	end
script.Parent.Parent.Pitchforkitem.Handle.Touched:connect(onTouched)
tool.Equipped:connect(Equipped)
tool.Unequipped:connect(unEquipped)

Output1: Attempt to connect failed: Passed value is not a function Output2: Attempt to call nil value Please help before i go insane!!! Thank you!!!

4 comments

0

you changed it, what is the output now?

0

I am getting a new one along with the attempt to call nil value

0

set name=tool.Parent.Name instead, because the tool is going to be inside of the character and not the backpack.

0

You're declaring the other two functions inside of the first one, so they don't exist yet.