How to make a script where when a player obtains a badge, it sends a system chat announcing that the player has obtained a badge?

So, did you changed local script like this?

game.ReplicatedStorage.SendChatRemote.OnClientEvent:Connect(function(data)
		game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", data)
end)

He literally does not need that now either.

image
Thank you, it works now! Ill add the server script code to the rest of the badges.

Btw, you accidentally put the line twice lol

1 Like

oofs, I have to edit lol thanks for telling me

I recommend adding @ to know it’s display name or username!

Alright, thank you! Depends if ill do it.

Hello! I know this is something old but I tried to do everything they said here but step 3 for some reason gives me an error most likely I’m doing something wrong but I don’t know much about scripting so… :confused:

If someone answers this I need help pls

my english is not very good but, you need to change PlayerNameHere to plr.Name

if you have any other problems, let me know, I’ll be happy to help you.

so i just have to change PlayerNameHere for what you said or do i have to add something else?

Well I tried to do it and it didn’t work it gives me this error I don’t know what it means :frowning:
image

sorry for not answering, could you give me the script to fix it?

1 Like

Well this is the script, it is supposed that when you touch a Part it will give you the bagde of this if it works but not the message, I did what it said to put the script after the ‘‘AwardBagde’’ but I don’t know if I did it right
Script:

local badgeservice = game:GetService(“BadgeService”)
local id = (2129068666)
script.Parent.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	badgeservice:AwardBadge(plr.UserId, id)
	game.ReplicatedStorage.SendChatRemote:FireAllClients({
		Text = (plr.Name " got [BADGENAME] Badge!!"); --The chat message
		Color = Color3.fromRGB(255, 255, 0); --Chat message color, defaults to white
		Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
		TextSize = 18 --Text size, defaults to 18
	})             
	
end

end)

Ok I fixed your script and this is the result

local badgeservice = game:GetService("BadgeService")
local id = 0 --Put your id here

local serverScriptService = game:GetService("ServerScriptService")

local debounce = false
local Cooldown = 3 --Cooldown for avoid spam from Touched Event

local Part = script.Parent
Part.Touched:Connect(function(HitPlr)
	if debounce then return end
	debounce = true
	--BadgeGiver--
	if HitPlr.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(HitPlr.Parent.Name) then
		local Player = game.Players[HitPlr.Parent.Name]
		if not game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId, id) then
			badgeservice:AwardBadge(Player.UserId, id)
			game.ReplicatedStorage.SendChatEvent:FireAllClients(Player.Name.. " Got [BadgeName] Badge!!");
		end
	end
	--Cooldown
	task.wait(Cooldown)
	debounce = false
end)

I added a cooldown because the Touched function was running too many times when you touched it.

I also need you to remove the local script that received the text and add this script in a localscript on StarterPlayer, StarterPlayerScripts, and paste this script:

game.ReplicatedStorage.SendChatEvent.OnClientEvent:Connect(function(message)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = message;
		Color = Color3.fromRGB(255, 255, 0);
		Font = Enum.Font.SourceSansBold;
	})
end)

Also don’t forget to create a RemoteEvent in Replicated Storage called SendChatEvent.

that’s all I could do, as I’m not good at scripting.

but I hope this can really help you.

4 Likes

YESS!!! NOW WORK THX SO MUCH :smiley:

1 Like