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

Passed Value Is Not A Function()?

alright so i made a very simple chat emote system but then i ran into the issue of course where the animations dont stop so i hooked it up to all humanoid events that stop animations and then it started erroring and acting like my function doesnt even exist

LocalScript:

local Character = script.Parent
local Player = game.Players.LocalPlayer
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Instance.new("Animation")
Animation.Name = "CustomDance"
local emote = ""

function Emote()
	if emote == "dance4" then
		Animation.AnimationId = "rbxassetid://4849366774"
		--Animation.Looped = true
		local animationTrack = Humanoid:LoadAnimation(Animation)
		animationTrack:Play()
	elseif emote == "justice" then
		Animation.AnimationId = "rbxassetid://4849331061"
		--Animation.Looped = true
		local animationTrack = Humanoid:LoadAnimation(Animation)
		animationTrack:Play()
	end
end

function StopAnims()
	local ActiveTracks = Humanoid:GetPlayingAnimationTracks()
	for _,v in pairs(ActiveTracks) do
		if v.Name == "CustomDance" then
	    	v:Stop()
		end
	end
end

Player.Chatted:Connect(function(msg)
	if (string.sub(msg, 1, 3) == "/e ") then
		emote = string.sub(msg, 4)
		Emote()
	elseif (string.sub(msg, 1, 7) == "/emote ") then
		emote = string.sub(msg, 8)
		Emote()
	end
end)

Humanoid.Died:Connect(StopAnims())
Humanoid.Running:Connect(StopAnims())
Humanoid.Jumping:Connect(StopAnims())
Humanoid.Climbing:Connect(StopAnims())
Humanoid.GettingUp:Connect(StopAnims())
Humanoid.FreeFalling:Connect(StopAnims())
Humanoid.FallingDown:Connect(StopAnims())
Humanoid.Seated:Connect(StopAnims())
Humanoid.PlatformStanding:Connect(StopAnims())
Humanoid.Swimming:Connect(StopAnims())

1 comment

0

Did you try removing the brackets when connecting? (not all just the extra ones)

1 answer

✓ Accepted answer

When you connect functions to events, you have to connect the function itself e.g. event:Connect(someFunction). You shouldn't call the function while trying to connect it e.g. event:Connect(someFunction()) this is wrong.

Calling the function while trying to connect it is wrong because Connect() requires a function as the input. When you call a function while trying to connect it, you are passing the value returned by the function to the Connect() function.

Let's say we have someFuction:

local someFunction()
    return true
end

When we do event:Connect(someFunction()), it evalutes to event:Connect(true) because someFunction() returns true. Since Connect expects a function as input, it throws the error "Passed Value Is Not A Function". The correct code would be event:Connect(someFunction).

1 comment

0

Sweet dude thank you so much this helped out a lot!

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