Model cloning in the same position

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)

image

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.

What does this value refer to? It seems like they’re only going to one CFrame because you’re only referencing the CFrame of one instance.


The value refer to these parts.

Could you be more specific? At the moment it looks like you have one DropperCF instance per plot, which would suggest one CFrame value per player plot - unless I’m missing something.

Yes, I have one per plot, but the PlotModel refers to the Plot that the player own as you can see on the script

That’s not the issue I have with your code. The problem lies in the fact that there is only one CFrame value being passed for every dropper that the player might own. In this way, every dropper instance will obviously only go to a singular CFrame. The only way I see this not being the case is if there is information you haven’t posted concerning the DropperCF value (or the general layout of how players interact with plots).

1 Like

I found the problem, and the only cause of the problem was because I’m dumb lol. The problem is that all the CF were inside PlotA, sorry for the lost time :slight_smile: