You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I would like my script to work and to send a message to my discord server whenever someone completes the level. -
What is the issue? Include screenshots / videos if possible!
As you can see, it sends multiple times, and it is very annoying.
Also here, i cannot find the problem and it is very confusing me!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
My tried solutions are in the text block
local teleportPart = script.Parent
local teleportPlaceId = 128946683861217 -- Replace with your target game Place ID
local levelCap = 1
local value = 0
local httpservice = game:GetService("HttpService")
local url = "exampleURL"
local leavingplayers = {}
local notifiedPlayers = {}
local colors = {
["join"] = 4660456,
["leave"] = 16718924,
["go"] = 63882,
["achieve"] = 16769357,
}
local function datasend(player, action, color)
if player and not notifiedPlayers[player.UserId] then
local tries = 0
if player.UserId == 331550209 then
return
end
if player.UserId == 1 then
return
end
local description = player.Name..action.."\nhttps://www.roblox.com/users/"..player.UserId.."/profile/"
local data = {
['embeds'] = {{
['title'] = player.Name,
['description'] = description,
['color'] = color,
['footer'] = {
['text'] = os.date("%x").. " " .. os.date("%X"),
["icon_url"] = "https://images-ext-1.discordapp.net/external/2dZVVL6feMSM7lxfFkKVW__LToSOzmToSEmocJV5vcA/https/cdn.discordapp.com/embed/avatars/0.png",
}
}}
}
local data_completed = httpservice:JSONEncode(data)
local success = pcall(function()
httpservice:PostAsync(url,data_completed)
end)
if not success and tries < 5 then
repeat
tries += 1
data_completed = httpservice:JSONEncode(data)
httpservice:PostAsync(url,data_completed)
until success or tries == 5
end
end
local TeleportService = game:GetService("TeleportService")
local privateServerCode = TeleportService:ReserveServer(teleportPlaceId)
local function onTouch(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not notifiedPlayers[player.UserId] then
if player and not notifiedPlayers[player.UserId] and value == 0 then -- tried doing this If statement twice
datasend(player, " has beaten 1-1!", colors.achieve)
value = 1 -- tried doing a debounce
wait(0.3)
value = 0
end
notifiedPlayers[player.UserId] = true
for i,v in pairs(player.Quests:GetChildren()) do
if v.Value == "Beat level 1-1 In Platformer!" then
v.Completion.Value = v.Completion.AmountNeeded.Value
end
end
TeleportService:TeleportToPrivateServer(teleportPlaceId, privateServerCode, {player}, nil, {
PlayerTeleportTimeout = 10
})
teleportPart.crumble.Enabled = true
teleportPart.crumble2.Enabled = true
teleportPart.crumble3.Enabled = true
teleportPart.Sound:Play()
wait(3)
teleportPart.crumble.Enabled = false
teleportPart.crumble2.Enabled = false
teleportPart.crumble3.Enabled = false
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local level = leaderstats:FindFirstChild("Level")
if level and level.Value < levelCap then
level.Value = level.Value + 1
end
end
end
end
teleportPart.Touched:Connect(onTouch)