wait(1)
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
workspace.SpawnPart.Button.ClickDetector.createPart.OnClientEvent:Connect(function()
for i, v in pairs(ReplicatedStorage:GetChildren()) do
if v.Name == player.leaderstats.Color.Value then
part = v:Clone()
break
end
end
local multiplier = part:WaitForChild("PartMultiplier").Value
game:GetService("ReplicatedStorage").plusPart:FireServer(player, multiplier)
part.Owner.Value = player.Name
part.Parent = workspace
part.Position = Vector3.new(math.random(-21, 23.5), 17, math.random(-41.25, -24))
wait(2)
part:Destroy()
-- CreatePart()
end)
I am doing that already.
Here are my script changes:
local DataStoreService = game:GetService("DataStoreService")
local PartsStore = DataStoreService:GetDataStore("playerPartsSave")
--Create Leaderstats
game:GetService("Players").PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player) --Leaderstats
leaderstats.Name = "leaderstats"
local Parts = Instance.new("IntValue", leaderstats) --Parts
Parts.Name = "Parts"
local PartColor = Instance.new("StringValue", leaderstats) --PartColor
PartColor.Name = "Color"
PartColor.Value = "WhitePart"
--Load Data
local playerUserID = ("Player_" .. player.UserId)
local success, errorMessage = pcall(function()
data = PartsStore:GetAsync(playerUserID)
end)
if success then
print("Player Data Loaded")
Parts.Value = data
print(data)
else
print("Player's data wen't no")
end
end)
--Add Parts RemoteEvent
game:GetService("ReplicatedStorage").plusPart.OnServerEvent:Connect(function(player, multiplier)
player:WaitForChild("leaderstats"):WaitForChild("Parts").Value += multiplier.Value
end)
--Save Data
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = ("Player_" .. player.UserId)
local data = player.leaderstats.Parts.Value
local success, errorMessage = pcall(function()
PartsStore:SetAsync(playerUserID, player.leaderstats.Parts.Value)
end)
if success then
print("Data Saved")
else
print("Data Fricked Up")
end
end)