My 'broadcast' script isn't working!

Alright so I’m trying to make a chat notification when someone in my game earns a badge, and the way I’m testing it is firing a remote event on all clients when the game starts. However, when I playtest it, it doesn’t work.

broadcast.OnClientEvent:Connect(function(message : string)
	if not game:IsLoaded() then
		print("not loaded")
		game.Loaded:Wait()
	end
	print("Game has been loaded")
	textChatService.TextChannels.RBXGeneral:DisplaySystemMessage("<font color=\"rgb(50,255,0)\">"..message.."</font>")
	displayer:DisplaySystemMessage("WASSUp")
end)

Even the last line of code that displays “WASSUp” doesn’t work, which is really confusing. The print statements work, though.

3 Likes

why dont you just make it fire on the server, so once he earns it on the client side, fire a remote event on the server side that announces it in the chat

1 Like

Did you just understood what you said?

1 Like

Are you using LegacyChatService or the new one?

You perhaps forgot to write TextChatService.CreateDefaultTextChannels?

game.TextChatService.CreateDefaultTextChannels = true
repeat task.wait() until game:IsLoaded()
game.Players.PlayerAdded:Connect(function(plr)
   task.wait(3)
   game.ReplicatedStorage.Broadcast:FireAllClients(plr.Name..' joined!')
end)
local tcs = game:GetService('TextChatService')
game.ReplicatedStorage.Broadcast.OnClientEvent:Connect(function(msg)
   tcs.TextChannels.RBXGeneral:DisplaySystemMessage("<font color='rgb(255,0,0)'>"..msg.."</font>"
end)

Doesn’t work, causes error

I’m using TextChatService, so I’m pretty sure it’s the new one

Thank you! It worked! Me so happy :slight_smile:

2 Likes
--Badge Award Check; ServerScript in ServerScriptService
local broadcast = game:GetService("ReplicatedStorage"):WaitForChild("Broadcast")
local BadgeService = game:GetService("BadgeService")
local badgeId, debounce = 123456789, {} --replace badgeId

game.Players.PlayerAdded:Connect(function(player) --gameloaded() workaround
	player.CharacterAdded:Connect(function(character) --one spawn debounce 
		if not debounce[player.UserId] then debounce[player.UserId] = true
			local humanoid = character:WaitForChild("Humanoid") task.wait(0.99)
			local success, hasBadge = pcall(function() --stalled for OnClientEvent
				return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
			end)

			if success and not hasBadge then
				pcall(function() BadgeService:AwardBadge(player.UserId, badgeId)
					broadcast:FireAllClients(player.Name .. " earned a badge!")
				end)
			end
		end
	end)
end)
--Badge Award Message; ClientScript in StarterPlayerScripts or StarterGui
local broadcast = game:GetService("ReplicatedStorage"):WaitForChild("Broadcast")
local textChatService,channel = game:GetService("TextChatService"), nil

repeat task.wait(0.33) channel = textChatService
	.TextChannels:FindFirstChild("RBXGeneral") --loads after gameloaded()
until(channel)

broadcast.OnClientEvent:Connect(function(message)
	channel:DisplaySystemMessage("<font color=\"rgb(50,255,0)\">"..message.."</font>")
	channel:DisplaySystemMessage("WASSUp")
end)
2 Likes

Well actually, we don’t have to worry about that, this was merely for testing. However, thanks for the effort!

1 Like

No worries, basically went off your description. I did just delete a solution, so …

1 Like

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