Hey there,
I have this messaging service script and webhook that updates across every server. That all works fine but in the messaging service script I have it put the message into a string value, Then in the webhook when i try and get that value it says its nil?
Webhook:
local PetWebhookModule = {}
--// Services
local HttpService = game:GetService("HttpService")
--// URL
local webhookUrl = ""
local GetWebhookColor = function(rarity)
if rarity == "Legendary" then
return 16766976
elseif rarity == "Mythic" then
return 65280
elseif rarity == "Mystery" or rarity == "Secret" then
return 1059548
end
return 16766976
end
function PetWebhookModule:SendWebhook(Player, PetName, Rarity, Chance)
if script.WebhookOn.Value == false then return end
--// ^^ REMOVE
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("SecStats")
local secs = game.ReplicatedStorage.SecretsHatched
secs.UniThing.Value = secs.UniThing.Value + 1
local counter = game.ReplicatedStorage.Value.Value
if Player ~= nil and PetName ~= nil and Rarity ~= nil and Chance ~= nil then
spawn(function()
print(counter)
local color = GetWebhookColor(tostring(Rarity))
local data = HttpService:JSONEncode({
["embeds"] = {{
["title"] = "Someone Hatched A ".. tostring(Rarity).." ".. tostring(PetName).." Pet (".. tostring(Chance)..")!",
["description"] = "Player: ".. tostring(Player.Name).. " Amount Hatched: "..counter,
["color"] = (color or 16766976),
}}
})
if data ~= nil then
HttpService:PostAsync(webhookUrl, data)
end
end)
end
end
return PetWebhookModule
Publish message script:
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local MESSAGING_TOPIC = "SecHatch"
local updateLabelEvent = Instance.new("RemoteEvent")
updateLabelEvent.Parent = game.ReplicatedStorage
updateLabelEvent.Name = "UpdateSecCounter"
Players.PlayerAdded:Connect(function(player)
local secs = game.ReplicatedStorage:WaitForChild("SecretsHatched").UniThing
-- Subscribe to the topic
local subscribeSuccess, subscribeConnection = pcall(function()
return MessagingService:SubscribeAsync(MESSAGING_TOPIC, function(message)
updateLabelEvent:FireClient(player, message.Data)
end)
end)
if subscribeSuccess then
updateLabelEvent:FireClient(player, secs.Value)
-- Unsubscribe from topic upon player ancestry change
player.AncestryChanged:Connect(function()
subscribeConnection:Disconnect()
end)
end
-- Publish to topic
secs.Changed:Connect(function()
local publishSuccess, publishResult = pcall(function()
local message = secs.Value
MessagingService:PublishAsync(MESSAGING_TOPIC, message)
end)
if not publishSuccess then
updateLabelEvent:FireClient(player, publishResult)
end
end)
end)
Recive message script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local updateLabelEvent = ReplicatedStorage:WaitForChild("UpdateSecCounter")
local function onUpdateLabel(str)
ReplicatedStorage.Value.Value = str
script.Parent.Text = str
end
updateLabelEvent.OnClientEvent:Connect(onUpdateLabel)
Output: