Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.0 kB
1
Indexable
Never
Apologies for the oversight. I made a mistake in updating the leaderstat value. Here's an updated version of the code that correctly updates the leaderstat value with the player's baseplate size:

```lua
-- Load the PlayerService and DataStoreService
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local dataStoreName = "BaseplateSizeDataStore" -- Change this to your preferred name

-- Function to calculate and set the baseplate size for a player
local function setBaseplateSize(player)
    local baseplate = player.Character and player.Character:FindFirstChild("Baseplate")
    if baseplate then
        local currentSize = baseplate.Size.X
        local newSize = currentSize + 2 -- Increase the size by 1 stud on all sides to create a square
        baseplate.Size = Vector3.new(newSize, 1, newSize)

        -- Save the updated size
        local dataStore = DataStoreService:GetDataStore(dataStoreName)
        dataStore:SetAsync(player.UserId, newSize)
    end
end

-- Function to update the leaderstat for a player
local function updateLeaderstat(player)
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local baseplateSize = leaderstats:FindFirstChild("BaseplateSize")
        if baseplateSize then
            local baseplate = player.Character and player.Character:FindFirstChild("Baseplate")
            if baseplate then
                local size = baseplate.Size.X
                baseplateSize.Value = size
            end
        end
    end
end

-- Function to save the player's baseplate size when they leave
local function saveBaseplateSize(player)
    local dataStore = DataStoreService:GetDataStore(dataStoreName)
    local baseplate = player.Character and player.Character:FindFirstChild("Baseplate")
    if baseplate then
        local size = baseplate.Size.X
        dataStore:SetAsync(player.UserId, size)
    end
end

-- Listen for player joining
game.Players.PlayerAdded:Connect(function(player)
    -- Create the leaderstats and BaseplateSize value if they don't exist
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local baseplateSize = Instance.new("IntValue")
    baseplateSize.Name = "BaseplateSize"
    baseplateSize.Value = 0
    baseplateSize.Parent = leaderstats

    -- Set the initial baseplate size for the player
    setBaseplateSize(player)

    -- Update the leaderstat for the player every second
    while wait(1) do
        updateLeaderstat(player)
    end
end)

-- Listen for player leaving
game.Players.PlayerRemoving:Connect(function(player)
    -- Save the player's baseplate size
    saveBaseplateSize(player)
end)
```

Now, the `updateLeaderstat` function correctly updates the `BaseplateSize` value in the player's `leaderstats` folder with the current baseplate size.