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.
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
--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)