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

Attempt to connect failed: Passed value is not a function?

I'm having a bit of trouble seeing what exactly is wrong with my script. It looks completely fine to me but it doesn't work because I can't get the function to fire off because it says that my function (hurtcalc) is apparently not defined.

Here is the code (it's a globalscript) and thank you in advance for helping me.

local Tool = script.Parent.Parent
swing1 = Tool:FindFirstChild("attackState1")
swing2 = Tool:FindFirstChild("attackState2")
aerial = Tool:FindFirstChild("aerialstate")
boxActive = Tool.boxActive

hurt = script.Parent.damage.Value



local function onTouched(hit)
	while boxActive.Value == true do
		if hit.Parent:findFirstChild("Humanoid") then
			hit.Parent["Humanoid"]:TakeDamage(hurt.Value)
			wait()
		end
end

local function hurtcalc()
	if aerial.Value == true then
		hurt.Value = 10
		print "damage 10"
		return hurt.Value
	elseif swing1.Value == true then
		hurt.Value = 20
		print "damage 20"
		return hurt.Value
	elseif swing2.Value == true then
		hurt.Value = 15
		print "damage 15"
		return hurt.Value
		end
	script.Parent.Touched:Connect(onTouched)
	end
end
	
script.Parent:GetPropertyChangedSignal("Transparency"):Connect(hurtcalc)

1 answer

✓ Accepted answer

You have misplaced end keywords. So your hurtcalc is actually local to the definition of onTouched, where it doesn't get used or called, and then hurtcalc is out of scope at the last line of the script.

Add another end after the onTouched logic, and remove one end after the hurtcalc logic.

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