#I just need when the player enters he takes the Tool

7 messages · Page 1 of 1 (latest)

mint venture
#

Here script

#

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local HttpService = game:GetService("HttpService")
local DataStore = DataStoreService:GetDataStore("CodeDataStore_V1")

local codesToTools = {
["20KMN"] = {toolName = "HandCuffsGift", duration = 345600},
}

local WEBHOOK_URL = "https://discord.com/api/webhooks/1280286062345982147/kcqFICNJYXQZmy9a0wEt337z5Y28lOBjV5r3l2ObcwFdtpU5CxtCtdBaPeRZIwNRlqaa"

local function sendDiscordNotification(player, code, toolName)
local embed = {
title = "Code Redeemed",
description = "Player redeemed a code",
color = 0x00FF00,
fields = {
{
name = "اللاعب",
value = string.format("%s", player.Name, player.UserId),
inline = true
},
{
name = "الكود",
value = code,
inline = true
},
{
name = "اسم التول الي اخذها",
value = toolName,
inline = true
},
{
name = "الوقت",
value = os.date("%I:%M %p", os.time()),
inline = true
},
{
name = "تاريخ انشاء حسابه",
value = player.AccountAge .. " days ago",
inline = true
}
},
footer = {
text = "تم استخدام كود هدايا"
}
}

local success, err = pcall(function()
    HttpService:PostAsync(
        WEBHOOK_URL,
        HttpService:JSONEncode({embeds = {embed}}),
        Enum.HttpContentType.ApplicationJson
    )
end)

if not success then
    warn("Failed to send Discord notification: " .. err)
end

end

local function removeToolFromPlayer(player, toolName)
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
for _, item in pairs(backpack:GetChildren()) do
if item.Name == toolName then
item:Destroy()
end
end
end
end
local function handleToolExpiration(userId, toolName)
local player = Players:GetPlayerByUserId(userId)
if player then
removeToolFromPlayer(player, toolName)
end
end

local function onPlayerAdded(player)
local userId = player.UserId

for code, data in pairs(codesToTools) do
    local codeKey = userId .. "_code_" .. code
    local expirationTime
    local currentTime = os.time()

    local success, err = pcall(function()
        expirationTime = DataStore:GetAsync(codeKey)
    end)

    if not success then
        warn("Failed to get expiration time: " .. err)
        return
    end

    if expirationTime and expirationTime > currentTime then
        local tool = ServerStorage:FindFirstChild(data.toolName)
        if tool then
            local toolClone = tool:Clone()
            toolClone.Parent = player.Backpack

            -- Schedule tool removal
            delay(data.duration, function()
                handleToolExpiration(userId, data.toolName)
            end)
        else
            warn("Tool not found: " .. data.toolName)
        end
    end
end

end

local function onCodeSubmitted(player, enteredCode)

#

local codeData = codesToTools[enteredCode]
if not codeData then
return
end

local userId = player.UserId
local codeKey = userId .. "_code_" .. enteredCode
local currentTime = os.time()

local codeUsed
local success, err = pcall(function()
    codeUsed = DataStore:GetAsync(codeKey)
end)

if not success then
    warn("Failed to check if code was used: " .. err)
    return
end

if codeUsed then
    return
end

local expirationTime = currentTime + codeData.duration

success, err = pcall(function()
    DataStore:SetAsync(codeKey, expirationTime)
end)

if not success then
    warn("Failed to set expiration time: " .. err)
end

local tool = ServerStorage:FindFirstChild(codeData.toolName)
if tool then
    local toolClone = tool:Clone()
    toolClone.Parent = player.Backpack

    -- Schedule tool removal
    delay(codeData.duration, function()
        handleToolExpiration(userId, codeData.toolName)
    end)

    sendDiscordNotification(player, enteredCode, codeData.toolName)
else
    warn("Tool not found: " .. codeData.toolName)
end

end

game.ReplicatedStorage.Events:WaitForChild("CodeSubmitEvent").OnServerEvent:Connect(onCodeSubmitted)
game.Players.PlayerAdded:Connect(onPlayerAdded)

formal geyser
#

What the fuck

#

thanks for sending us your webhook???

mint venture
#

But