I'm making a custom chat system, and whenever I try to chat, it keeps spamming my chat with "Unable to cast value to function". Here is my code.

local chat = game:GetService('DataStoreService'):GetDataStore('GlobalChat')

local function UpdateChat()
	chat:SetAsync(5, chat:GetAsync(4))
	chat:SetAsync(4, chat:GetAsync(3))
	chat:SetAsync(2, chat:GetAsync(1))
	if plr.Name == 'hiimgoodpack' then
		print('Attempt to cast '..Filter(msg, plr))
		chat:SetAsync(1, tostring('[Owner]'..plr.Name..':'..tostring(Filter(msg, plr)))) --Whoops, forgot to add a return to the Filter function.
	else
		print('Attempt to cast '..Filter(msg, plr))											
                chat:SetAsync(1, tostring(plr.Name..':'..tostring(Filter(msg, plr))))
	end
end
		
local success = false
repeat
	wait()
	local s, m = pcall(UpdateChat)
	if s then
		success = true
	else
		warn('Could not update chat due to '..m)
	end
until success

Whenever I type something, it always says "Could not update chat due to Unable to cast value to function". Also, I tried :UpdateAsync and it had the same problem. I also tried doing it without a pcall, and it still errored. Also, if you guys could explain to me, what is the difference from :SetAsync and :UpdateAsync?

1 comment

0

The error is referring to the fact that it cannot "cast" a value into a ROBLOX object