Why is this code not Preforming in-game but it is in Roblox Studio

I want to acheive this thing in my coding where it would read whenever you type something in ingame chat and it sends it to the discord server through webhook

the Problem is that it doesn’t work trough in-game but it does it in studio

I have Tried Redoing the script over the last 2 days Neither Worked just did it in-Game

local http = game:GetService("HttpService")
local players = game:GetService("Players")
local webhook = "https://discord.com/api/webhooks/911812700806459473/skCSKy2hfzUa8JtKnNDDS02LiorDUkkch0-PBlFzn4o6cuGuPq8ZV_LK-vTvc-Aq0snm"


local function onChatted(plr, msg)
	local data = {
		content = string.format('`%s:` %s', plr.Name, msg)
	}

	local jsonData = http:JSONEncode(data)
	local response = http:PostAsync(webhook, jsonData)
end


local function onPlayerAdded(plr)
	plr.Chatted:Connect(function(msg) onChatted(plr, msg) end)
end


players.PlayerAdded:Connect(onPlayerAdded)
1 Like

That Webhook is Randomly Generated on a discord webhook that doesn’t exist I did this reply because I know those people who gonna take the ID and do some bad stuff with it

1 Like

It could be possible that the script is starting after the player is already in the game.

local http = game:GetService("HttpService")
local players = game:GetService("Players")
local webhook = ""


local function onChatted(plr, msg)
	local data = {
		content = string.format('`%s:` %s', plr.Name, msg)
	}

	local jsonData = http:JSONEncode(data)
	local response = http:PostAsync(webhook, jsonData)
end


local function onPlayerAdded(plr)
	plr.Chatted:Connect(function(msg) onChatted(plr, msg) end)
end

for _, plr in ipairs(players:GetPlayers()) do
	onPlayerAdded(plr)
end
players.PlayerAdded:Connect(onPlayerAdded)

If that doesn’t work then make sure you have HTTP requests enabled. (Although it might already be if this already works in studio.

1 Like

just checked i think this is why

1 Like

Discord webhooks only work in studio now. Not in game. Because discord blocked them. So sorry about that. There’s a way to bypass it tho. Check out this tutorial: How to use Discord webhooks with Roblox using a proxy server! - YouTube

That makes sense actually, as in edit mode the requests are being sent from your personal computer rather than Roblox’s servers.

1 Like

it is Working Now Thanks!

Have a Good Day to all!

Just Looked through this and saw ipairs. I asked my Friend and he never had heard of it neither have I.