Hi
I’m about to make a tycoon and I’m in the middle of data store scripting but I found some problems
this is the thing that you should see when you join the game after buying droppers
but I’m seeing this
this is my data store script:
local ProfileService = require(script:WaitForChild('ProfileService'))
local ProfileTemplate = {
cash = 10;
Items = {};
}
local ProfileStore = ProfileService.GetProfileStore(
"PlayerData",
ProfileTemplate
)
local Profiles = {}
local function playerAdded(player)
local Profile = ProfileStore:LoadProfileAsync("Player"..player.UserId)
if Profile then
Profile:AddUserId(player.UserId)
Profile:Reconcile()
Profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(game.Players) == true then
Profiles[player] = Profile
else
Profile:Release()
end
else
player:Kick()
end
end
game.Players.PlayerAdded:Connect(function(player)
playerAdded(player)
local Profile = Profiles[player]
if not Profile then warn('No Profile!') return end
local folder = Instance.new('Folder')
folder.Name = 'leaderstats'
folder.Parent = player
local cash = Instance.new('IntValue')
cash.Name = 'cash'
cash.Value = Profile.Data.cash or 10
cash.Parent = folder
cash:GetPropertyChangedSignal('Value'):Connect(function()
Profile.Data.cash = cash.Value
end)
game.ServerScriptService:WaitForChild('PlotHandler'):WaitForChild('CreatePlot'):Fire(player, Profile.Data.Items)
end)
game.Players.PlayerRemoving:Connect(function(player)
local Profile = Profiles[player]
if Profile then
Profile:Release()
end
end)
for _, player in game.Players:GetPlayers() do
task.spawn(playerAdded, player)
end
script:WaitForChild('ItemUnlocked').Event:Connect(function(player, ItemId)
local Profile = Profiles[player]
table.insert(Profile.Data.Items, ItemId)
end)
and this one is my plot handler:
local Plots = game.Workspace.Plots
local TemplatePlot = game.Workspace.TemplatePlot
local function getPlot(player)
for _, plot in Plots:GetChildren() do
local owner = plot:GetAttribute('Owner')
if not owner then continue end
if owner ~= player.UserId then continue end
return plot
end
end
local function getItemFromTemplatePlot(itemId)
for _, item in TemplatePlot.Items:GetChildren() do
if item:GetAttribute('Id') == itemId then
return item
end
end
end
local function LoadItems(player, itemIdsTable)
local plot = getPlot(player)
for _, itemId in itemIdsTable do
local item = getItemFromTemplatePlot(itemId)
if not item then continue end
local itemClone = item:Clone()
local itemCFrame
if itemClone:IsA('Model') then
itemCFrame = itemClone:GetPivot()
elseif itemClone:IsA('BasePart') then
itemCFrame = itemClone.CFrame
end
local reletiveItemCFrame = TemplatePlot.CFrame:ToObjectSpace(itemCFrame)
local worldCFrameOfNewPlot = plot.CFrame:ToWorldSpace(reletiveItemCFrame)
if itemClone:IsA('Model') then
itemClone:PivotTo(worldCFrameOfNewPlot)
elseif itemClone:IsA('BasePart') then
itemClone.CFrame = worldCFrameOfNewPlot
end
itemClone.Parent = plot.Items
end
end
script:WaitForChild('CreatePlot').Event:Connect(function(player, itemIdsTable)
for _, plot in Plots:GetChildren() do
if plot:GetAttribute("Taken") then continue end
plot:SetAttribute('Taken', true)
plot:SetAttribute('Owner', player.UserId)
print('Plot Has been given too '..player.Name..'!')
local ItemsFolder = Instance.new('Folder')
ItemsFolder.Name = 'Items'
ItemsFolder.Parent = plot
local TemplateButtons = TemplatePlot.Buttons:Clone()
local TemplateItems = TemplatePlot.Items
LoadItems(player, itemIdsTable)
for _, Button in TemplateButtons:GetChildren() do
if table.find(itemIdsTable, Button:GetAttribute('IdOfItemToUnlock')) then continue end
local ReletiveCFrame = TemplatePlot.CFrame:ToObjectSpace(Button:GetPivot())
Button:PivotTo(plot.CFrame:ToWorldSpace(ReletiveCFrame))
Button.buttonhead.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.parent)
if not player then return end
if plot:GetAttribute('Owner') ~= player.UserId then return end
if Button:GetAttribute('Debounce') then return end
Button:SetAttribute('Debounce', true)
task.wait(2, function()
if Button then
Button:SetAttribute('Debounce', false)
end
end)
local itemToUnlockId = Button:GetAttribute('IdOfItemToUnlock')
if not itemToUnlockId then warn('You forgot to add an IdOfItemToUnlock attribute') return end
local Price = Button:GetAttribute('Price')
if Price then
if player.leaderstats.cash.Value < Price then
warn('You Cant Afford This Item!')
return
end
player.leaderstats.cash.Value -= Price
end
for _, item in TemplateItems:GetChildren() do
if item:GetAttribute('Id') ~= itemToUnlockId then continue end
local itemClone = item:Clone()
local itemCFrame
if itemClone:IsA('Model') then
itemCFrame = itemClone:GetPivot()
elseif itemClone:IsA('BasePart') then
itemCFrame = itemClone.CFrame
end
local reletiveItemCFrame = TemplatePlot.CFrame:ToObjectSpace(itemCFrame)
local worldCFrameOfNewPlot = plot.CFrame:ToWorldSpace(reletiveItemCFrame)
if itemClone:IsA('Model') then
itemClone:PivotTo(worldCFrameOfNewPlot)
elseif itemClone:IsA('BasePart') then
itemClone.CFrame = worldCFrameOfNewPlot
end
for _, scriptObject in itemClone:GetDescendants() do
if scriptObject:IsA('BaseScript') then
scriptObject.Enabled = true
end
end
itemClone.Parent = ItemsFolder
Button:Destroy()
game.ServerScriptService.Data.ItemUnlocked:Fire(player, itemToUnlockId)
end
end)
Button.Parent = TemplateButtons
end
TemplateButtons.Parent = plot
break
end
end)
game.Players.PlayerRemoving:Connect(function(player)
for _, plot in Plots:GetChildren() do
if not plot:GetAttribute('Owner') then continue end
if plot:GetAttribute('Owner') ~= player.UserId then continue end
plot:SetAttribute('Taken', nil)
plot:SetAttribute('Owner', nil)
print('Plot Has been removed from '..player.Name..'!')
break
end
end)
can anybody help?
I’m not that professional in scripting