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