#How to make - when player died, the tools will remain in their backpack.

1 messages · Page 1 of 1 (latest)

keen herald
#
BuyToolsRemote.OnServerInvoke = function(player, toolName, price)
    local purchaseSuccessful = false
    local leaderstats = player:FindFirstChild("leaderstats")
    if not leaderstats then return false end

    local money = leaderstats:FindFirstChild("Money")
    if not money then return false end

    if typeof(toolName) ~= "string" or typeof(price) ~= "number" then
        return false -- Prevent remote spoofing
    end

    local function hasTool(player, toolName)
        -- Check Backpack
        if player:FindFirstChild("Backpack") and player.Backpack:FindFirstChild(toolName) then
            return true
        end
        -- Check Character
        if player.Character and player.Character:FindFirstChild(toolName) then
            return true
        end
        -- Check StarterGear
        if player:FindFirstChild("StarterGear") and player.StarterGear:FindFirstChild(toolName) then
            return true
        end
        return false
    end

    if hasTool(player, toolName) then
        return "alreadyOwned"
    end

    local tool = game.ServerStorage:FindFirstChild(toolName)
    if tool and tool:IsA("Tool") and money.Value >= price then
        money.Value -= price

        local clonedTool1 = tool:Clone()
        clonedTool1:SetAttribute("legit", true)
        clonedTool1:SetAttribute("serverToken", "🔥" .. tostring(os.time()))
        clonedTool1.Parent = player:FindFirstChild("Backpack")

        purchaseSuccessful = true
        end

    return purchaseSuccessful
end
light stone
#

prices should be stored on the server

#

In terms of saving the tool between deaths, I'd probably have a table of all owned tools (can be save do datastores too) and whenever the CharacterAdded event is triggered re-clone all the tools into the players backpack

keen herald