Well, I’m having a trouble that when players buy or load their save, the droppers are going to the same position, here’s the video showing it:
And the code:
Buy code:
local rs = game:GetService("ReplicatedStorage")
local func = rs:WaitForChild("BuyDropper")
func.OnServerInvoke = function(player, itemName, itemprice, itemlevel)
local PlotModel = workspace.Plots:FindFirstChild(player.Plot.Value)
local NewDropper = game.ServerStorage.Droppers:FindFirstChild(itemName)
local cash = player.properties.Money
local OldDropper = PlotModel.Objects.Dropper
local DropperCF = PlotModel.DropperCF
local DropperCF2 = PlotModel.DropperCF2.CFrame.Position
if cash.Value >= itemprice then
local DropClone = NewDropper:Clone()
DropClone.PrimaryPart = DropClone.Dropper
DropClone.Parent = PlotModel.Objects
DropClone.Name = "Dropper"
DropClone:PivotTo(CFrame.new(DropperCF.CFrame.Position))
player.properties.DropperLevel.Value = itemlevel
wait(.1)
OldDropper:Destroy()
cash.Value = cash.Value - itemprice
end
end
Load code:
local rs = game:GetService("ReplicatedStorage")
local Droppers = rs:WaitForChild("DropperLevels")
game.Players.PlayerAdded:Connect(function(player)
wait(5)
local dl = player.properties.DropperLevel.Value
local ml = player.properties.MaterialLevel.Value
local PlotModel = workspace.Plots:FindFirstChild(player.Plot.Value)
local PM = PlotModel.PartMaterial
if ml ~= "Plastic" then
--// Vars
if dl > 0 then
local dropper = Droppers:FindFirstChild('Dropper'..dl).Name
local NewDropper = game.ServerStorage.Droppers:FindFirstChild(dropper)
local DropperCF = PlotModel.DropperCF
local OldDropper = PlotModel.Objects.Dropper
local DropClone = NewDropper:Clone()
DropClone.PrimaryPart = DropClone.Dropper
DropClone.Parent = PlotModel.Objects
DropClone.Name = "Dropper"
DropClone:PivotTo(CFrame.new(DropperCF.CFrame.Position))
wait(.1)
OldDropper:Destroy()
end
--// Material
PM.Value = ml
end
end)
And the save code if you guys need:
local plr = game.Players
local DSS = game:GetService("DataStoreService")
local GDS = DSS:GetDataStore("PlayerData8")
plr.PlayerAdded:Connect(function(player)
local PlrID = 'Player'..player.UserId
local tab = Instance.new("Folder", player)
tab.Name = "properties"
--// Níveis
local MaterialLevel = Instance.new("StringValue", tab)
MaterialLevel.Name = "MaterialLevel"
local DropperLevel = Instance.new("IntValue", tab)
DropperLevel.Name = "DropperLevel"
--// Dinheiro
local dinheiro = Instance.new("IntValue", tab)
dinheiro.Name = "Money"
--// Plot
local plot = Instance.new("StringValue", player)
plot.Name = "Plot"
--// Data store
local data = GDS:GetAsync(PlrID)
if data then
dinheiro.Value = data["Money"]
DropperLevel.Value = data["DropperLevel"]
MaterialLevel.Value = data["MaterialLevel"]
else
dinheiro.Value = 20
DropperLevel.Value = 0
MaterialLevel.Value = "Plastic"
end
end)
local function create_table(player)
local playerstats = {}
for _, stat in pairs(player.properties:GetChildren()) do
playerstats[stat.Name] = stat.Value
end
return playerstats
end
plr.PlayerRemoving:Connect(function(player)
local playerstats = create_table(player)
local succes, err = pcall(function()
local plrId = 'Player'..player.UserId
GDS:SetAsync(plrId, playerstats)
end)
if not succes then
warn("could not save data")
end
end)
I don’t have tried anything at the moment because I don’t really know what is the cause of the problem. And if you need more information I can give it.