Untitled
unknown
plain_text
2 years ago
2.6 kB
6
Indexable
-- 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)
Editor is loading...