How to make a chat say,what someone got from clicking the button?

This is for the gambling thingy.I want to make it like this:“Player” got 50 EXP with the chance of 50% from gambling!

local GambleHere = script.Parent
local clickDetector = GambleHere:FindFirstChild("ClickDetector")

local rewards = {
	{ name = "Gold", amount = 250000000000, chance = 0.1 },
	{ name = "Gold", amount = 50, chance = 50},
	{ name = "Kromer", amount = 1, chance = 5 },
	{ name = "Kromer", amount = 10, chance = 1 },
	{ name = "XP", amount = 100, chance = 10 },
	{ name = "XP", amount = 10000, chance = 1 },
	{ name = "Weapon", weaponName = "Stick", requiredStats = { LOVE = 1, Resets = 0, TrueResets = 0 }, chance = 19.5 },
	{ name = "Weapon", weaponName = "Stick", requiredStats = { LOVE = 1, Resets = 0, TrueResets = 0 }, chance = 0.5 },
}

local function drawMessage(player, message)	 
	-- here
end

local function giveReward(player, reward)
	if reward.name == "Gold" then
		player.Gold.Value = player.Gold.Value + reward.amount
		drawMessage(player, "You have obtained " .. reward.amount .. " Gold!")
	elseif reward.name == "Kromer" then
		player.Kromer.Value = player.Kromer.Value + reward.amount
		drawMessage(player, "You have obtained " .. reward.amount .. " Kromer!")
	elseif reward.name == "XP" then
		player.XP.Value = player.XP.Value + reward.amount
		drawMessage(player, "You have obtained " .. reward.amount .. " EXP!")
	elseif reward.name == "Weapon" or reward.name == "AsgoreTrident" then
		local weaponName = reward.weaponName
		if player.Weapons:FindFirstChild(weaponName) and
			player.LOVE.Value >= reward.requiredStats.LOVE and
			player.Resets.Value >= reward.requiredStats.Resets and
			player.TrueResets.Value >= reward.requiredStats.TrueResets then
			if player.Weapons[weaponName].Value == false then
				player.Weapons[weaponName].Value = true
				drawMessage(player, "You have obtained the " .. weaponName .. "!")
			else
				drawMessage(player, "You already own this weapon!")
			end
		else
			drawMessage(player, "You don't meet the requirements for this weapon.")
		end
	end
end


local function trickOrTreat(player)
	local totalChance = 0
	local randomNum = math.random(100)

	for _, reward in ipairs(rewards) do
		totalChance = totalChance + (reward.chance or 0)
	end

	for _, reward in ipairs(rewards) do
		if randomNum <= reward.chance / totalChance * 100 then
			giveReward(player, reward)
			break
		else
			randomNum = randomNum - (reward.chance or 0)
		end
	end
end


if clickDetector then
	clickDetector.MouseClick:Connect(function(player)
		trickOrTreat(player)
	end)
else
	warn("ClickDetector not found!")
end

local respawnDelay = 60 

while true do
	clickDetector.MaxActivationDistance = 0
	wait(respawnDelay)
	clickDetector.MaxActivationDistance = 32
end

1 Like
--Only works for the new chat system and must run in a local script
local function sendSystemMessage(message: string): ()
	local TextChannels = game.TextChatService:WaitForChild("TextChannels")
	local RBXSystem: TextChannel = TextChannels:WaitForChild("RBXSystem")
	RBXSystem:DisplaySystemMessage(message)
end

--example usage
sendSystemMessage("<font color=\"rgb(255, 0, 0)\"><b>Hello!</b></font>")

If you want to send system messages to all players at once you will need replication code that sends the data through a remote to all players at once, then a local script picks it ups and runs the above code.

I may be dumb,but it doesn’t work now.
Like at all.

It must run in a local script and your game must be using the new chat system.

It still doesn’t work.
I don’t really know why.