Event won't happen

--FIRST SCRIPT (HANDLES ONSERVEREVENT)
local RepliStorage = game:GetService("ReplicatedStorage")
local emoteEvent = RepliStorage.sendEmote
local emotesFolder = RepliStorage:WaitForChild("Animations")

emoteEvent.OnServerEvent:Connect(function(player, emoteN)
	print("This print works.")
	if emoteN and emotesFolder:FindFirstChild(emoteN) then
		print("This print doesn't work.")
		local pEmotes = player.Emotes

		if not pEmotes:FindFirstChild(emoteN) then
			emotesFolder[emoteN]:Clone().Parent = pEmotes
			print("Player has now recieved an emote.")
		end
	end
end)
--SECOND SCRIPT (HANDLING FIRE EVENT)
while task.wait(0.1) do
	countDown -= 1
	clockMin = countDown/internalClockMin

	countValue.Value = clockMin
	countValue.Changed:Connect(function()
		countValue.Value = clockMin
	end)

	emoteText.Text = "next emote in "..string.format("%.2f", clockMin).." minutes..."
	if countDown == 0 then 
		task.wait(0.1) 
		countDown = 60 
		
		local emoteN
		repeat
			emoteN = emoteF[math.random(1, #emoteF)]
		until not folderEmote:FindFirstChild(emoteN)
		
		sendEmote:FireServer(emoteN)
		print("Lauched emote event.")
	end
end

The second script works as intended, it even fires the event. The first script only fires the first print, and somehow the second print just doesn’t… well, print. It already printed the emoteN and player (First Script).

Is it intended that you are setting emoteN until the folder doesn’t contain that emote? It’s kinda obvious why it failed to print the second print

emoteN keeps checking through the emoteF folder (it being the animations) until it sees that emoteN from emoteF is not in the player’s inventory (folderEmote)

And plus, both scripts (the two blocks of code) are different. The first being a ServerScript, and the second being a Local.

This condition prevents the code from continuing, it means that emoteN in emotesFolder doesn’t exist. Check if emoteN’s name matches with one emote in the emotesFolder in ReplicatedStorage
Try also printing the condition to see if it’s nil and changing FindFirstChild to WaitForChild. If it gives a warning then it doesn’t exist in emotesFolder

emoteN does match with an emote from the emotesFolder.
I’m trying the WaitForChild now.
And also, how do I print a condition?

EDIT: The WaitForChild doesn’t work.

Sorry my wording was a bit unclear, I mean you can print if FindFirstChild actually gives an object, not nil

print(emotesFolder:FindFirstChild(emoteN))

The problem should lie in the script not being able to find the object in emotesFolder

It prints nil. Although emoteN and one animation from emotesFolder match up (by name), it doesn’t print the object.

EDIT: Tried putting .Name next to emoteN, am now trying to see if it works.

It actually worked! Thanks for the help, kind stranger :slight_smile:

1 Like

I forgot FindFirstChild needs to be a string… well alright lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.