Script works in studio and not game?

I have a script to add XP my leaderstats value when a user types another users name and presses a button. It works perfectly fine and sends embeds to the discord when i run it in the studio environment. When I run it from the launcher the ouput just says this:
Game Output

When ran in studio the ouput is this:

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local addXPToPlayerEvent = ReplicatedStorage:WaitForChild("AddXPToPlayerEvent")
local showMessageEvent = ReplicatedStorage:WaitForChild("ShowMessageEvent")

local xpButton = script.Parent
local textBox = xpButton.Parent.Parent:WaitForChild("TextBox")


local function onXPButtonClick()
	local username = textBox.Text

	if username and username ~= "" then

		addXPToPlayerEvent:FireServer(username)
		print("Requested to add XP to: " .. username)
	else
		print("Please enter a valid username.")
	end
end


xpButton.MouseButton1Click:Connect(onXPButtonClick)


local function onShowMessage(message)
	if message == "SuccessMessageFrame" then
		print("XP added successfully.")
	elseif message == "NotFoundMessageFrame" then
		print("Player not found.")
	elseif message == "SelfMessageFrame" then
		print("You cannot add XP to yourself.")
	else
		print("Unexpected message: " .. message)
	end
end

showMessageEvent.OnClientEvent:Connect(onShowMessage)

Server Script - w/ Comments to help you track what its doing

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")

local addXPToPlayerEvent = Instance.new("RemoteEvent")
addXPToPlayerEvent.Name = "AddXPToPlayerEvent"
addXPToPlayerEvent.Parent = ReplicatedStorage

local showMessageEvent = Instance.new("RemoteEvent")
showMessageEvent.Name = "ShowMessageEvent"
showMessageEvent.Parent = ReplicatedStorage

local discordWebhookUrl = "My discord application link"

-- Function to send a log to Discord
local function sendLogToDiscord(title, description, color)
	local data = {
		["embeds"] = {{
			["title"] = title,
			["description"] = description,
			["color"] = color
		}}
	}

	local jsonData = HttpService:JSONEncode(data)
	print("Sending log to Discord: " .. jsonData)

	local success, response = pcall(function()
		return HttpService:PostAsync(discordWebhookUrl, jsonData, Enum.HttpContentType.ApplicationJson)
	end)

	if success then
		print("Successfully sent log to Discord.")
	else
		warn("Failed to send log to Discord: " .. tostring(response))
	end
end

-- Function to add XP to a specific player
local function addXPToPlayer(player, username)
	print("Attempting to add XP to player: " .. username .. " requested by: " .. player.Name)

	if player.Name == "LUFCarebest" then
		if username then
			local targetPlayer = Players:FindFirstChild(username)
			if targetPlayer then
				local leaderstats = targetPlayer:FindFirstChild("leaderstats")
				if leaderstats then
					local xpValue = leaderstats:FindFirstChild("XP")
					if xpValue then
						local oldXP = xpValue.Value
						xpValue.Value = oldXP + 99999999999
						local newXP = xpValue.Value
						showMessageEvent:FireClient(player, "SuccessMessageFrame")
						print("LUFCarebest added XP to player: " .. username)
						sendLogToDiscord("XP Added Successfully", "LUFCarebest added XP to " .. username .. ". Old XP: " .. oldXP .. ", New XP: " .. newXP, 3066993)
					else
						print("XP value not found for player: " .. username)
						sendLogToDiscord("XP Addition Failed", "XP value not found for player: " .. username, 15158332)
					end
				else
					print("leaderstats not found for player: " .. username)
					sendLogToDiscord("XP Addition Failed", "leaderstats not found for player: " .. username, 15158332)
				end
			else
				showMessageEvent:FireClient(player, "NotFoundMessageFrame")
				print("Player not found: " .. username)
				sendLogToDiscord("XP Addition Failed", "Player not found: " .. username, 15158332)
			end
		end
		return
	end

	if player.Name == username then
		showMessageEvent:FireClient(player, "SelfMessageFrame")
		print("Player cannot add XP to themselves: " .. username)
		sendLogToDiscord("XP Addition Failed", player.Name .. " tried to add XP to themselves.", 15158332)
		return
	end

	local targetPlayer = Players:FindFirstChild(username)
	if targetPlayer then
		local leaderstats = targetPlayer:FindFirstChild("leaderstats")
		if leaderstats then
			local xpValue = leaderstats:FindFirstChild("XP")
			if xpValue then
				local oldXP = xpValue.Value
				xpValue.Value = oldXP + 99999999999
				local newXP = xpValue.Value
				showMessageEvent:FireClient(player, "SuccessMessageFrame")
				print("Added XP to player: " .. username)
				sendLogToDiscord("XP Added Successfully", player.Name .. " added XP to " .. username .. ". Old XP: " .. oldXP .. ", New XP: " .. newXP, 3066993)
			else
				print("XP value not found for player: " .. username)
				sendLogToDiscord("XP Addition Failed", "XP value not found for player: " .. username, 15158332)
			end
		else
			print("leaderstats not found for player: " .. username)
			sendLogToDiscord("XP Addition Failed", "leaderstats not found for player: " .. username, 15158332)
		end
	else
		showMessageEvent:FireClient(player, "NotFoundMessageFrame")
		print("Player not found: " .. username)
		sendLogToDiscord("XP Addition Failed", "Player not found: " .. username, 15158332)
	end
end

-- Connect the remote event to the function
addXPToPlayerEvent.OnServerEvent:Connect(function(player, username)
	print("Received XP addition request from: " .. player.Name .. " for user: " .. username)
	addXPToPlayer(player, username)
end)

1 Like

Considering not even the OnServerEvent print is in the output, it is possible it’s not even receiving the client’s FireServer call. Are you sure its being fired in-game?

Also, are there any other F9 errors relating to these scripts in-game?

1 Like

No other F9 errors, I have even asked chat gpt what it thinks and it is struggling to find an answer.

Its weird how the server script outputs work in studio but are non-existent in the actual launcher.

1 Like

Ill add a statement to verify the server script is being fired from the client

2 Likes

Are you using a genuine DISCORD webhook?
Roblox forbids them outside of studio

You’ll need to use a webhook proxy, search it up

2 Likes

Make sure the connection is being set. Add a print under where you declare the OnServerEvent to ensure its connected.

1 Like

This could be the issue, but it’s not even seeing the client’s remote fire since it didn’t print. It might be another issue

1 Like

Maybe, but it really looks like the remote event was done properly

The webhook is a ROBLOX integration

This is the emebed from in studio

Better chance using guilded rather then discord you recon? I’m not paying for a proxy server

From what I know, there are free ones where you just have to replace the “discord” in the webhook link with a proxy name and it will work

Used a proxy with a free trial, same issue. XP gets added in studio aswell but not in-game

Possibly Roblox blocked that proxy link too?
I found this on the devforum

with the f9 console are you switching between CLIENT and SERVER?
studio output prints both, in-app you’ll only see CLIENT output messages.
if you have creator access in-game then you should have the ability to switch to SERVER
(i had to wait a few seconds for the developer console to update to let me view the server)

Yep checked both nothing there

Are HTTP requests enabled in game settings?
I don’t know if this would cause a silent error, though. I’d guess not.