DataService Help Update

So I got this far with another scripter looking to see if there is anymore insight? Im using a data store system for an inventory. And looking to use this script to add to the data store service without breaking the other store script. This basically creates a leader stats folder under already created data_folder. Im getting errors at end) and wondering if this is even possible?

local DataStoreService = game:GetService("DataStoreService")
if DataStoreService then
local data = DataStoreService:GetDataStore("Data_folder")
local Leaderstats = game:WaitForChild("Leaderstats")
	

game.Players.PlayerAdded:Connect(function(Player)
		
	if Player then
		local Leaderstats = Instance.new("Folder")
		Leaderstats.Name = "leaderstats"
		Leaderstats.Parent = Player
		local Cash = Instance.new("IntValue")
		Cash.Name = "Dragoons"
		Cash.Value = data:GetAsync(Player.UserId) or 250
		data:SetAsync(Player.UserId, Player.leaderstats.Dragoons.Value)
		Cash.Parent = Leaderstats
		local Resource1 = Instance.new("IntValue")
		Resource1.Name = "Wood"
		Resource1.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Wood.Value)
		Resource1.Parent = Leaderstats
		local Resource2 = Instance.new("IntValue")
		Resource2.Name = "Iron"
		Resource2.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Iron.Value)
		Resource2.Parent = Leaderstats
		local Resource3 = Instance.new("IntValue")
		Resource3.Name = "Stone"
		Resource3.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Stone.Value)
		Resource3.Parent = Leaderstats
		local Resource4 = Instance.new("IntValue")
		Resource4.Name = "Metal"
		Resource4.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Metal.Value)
		Resource4.Parent = Leaderstats
		local Resource6 = Instance.new("IntValue")
		Resource6.Name = "Cloth"
		Resource6.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Cloth.Value)
		Resource6.Parent = Leaderstats

	-- Adds 250 cash every 2 minutes
	if Cash then 
		while true do
			wait(2)
			Cash.Value = Cash.Value + 250					
		end			
end)
	
	
game.Players.PlayerRemoving:Connect(function(Player)
	data:SetAsync(Player.UserId, Player.leaderstats.Dragoons.Value) --Change "Points" to the name of your leaderstat.
	data:SetAsync(Player.UserId, Player.leaderstats.Wood.Value)	
	data:SetAsync(Player.UserId, Player.leaderstats.Iron.Value)
	data:SetAsync(Player.UserId, Player.leaderstats.Stone.Value)
	data:SetAsync(Player.UserId, Player.leaderstats.Metal.Value)
	data:SetAsync(Player.UserId, Player.leaderstats.Cloth.Value)	
end)

What are the errors at end)

Can you screenshot the output window?

oof that’s difficult to read - could you screenshot that next time?

looks like you’re missing an end somewhere. Perhaps here?
image

Yaa just noticed that, sorry about the screenshot. The first end) with the underlined ) went away

However the last line is still underlined red from( , Player to end)

Format document and it will show you where things start to go wrong with your end statements.

Screen Shot 2024-03-27 at 5.45.47 PM

1 Like

Says function at line 55 which is the Player removing function.

Missing an end statement here too:
image

If I take away “if DataStoreService then”

And change GetService to, WaitForService it clears errors think this will work?

Code with no error:

local DataStoreService = game:WaitForService("DataStoreService")
local data = DataStoreService:GetDataStore("Data_folder")
local Leaderstats = game:WaitForChild("Leaderstats")
	

game.Players.PlayerAdded:Connect(function(Player)
		
	if Player then
		local Leaderstats = Instance.new("Folder")
		Leaderstats.Name = "leaderstats"
		Leaderstats.Parent = Player
		local Cash = Instance.new("IntValue")
		Cash.Name = "Dragoons"
		Cash.Value = data:GetAsync(Player.UserId) or 250
		data:SetAsync(Player.UserId, Player.leaderstats.Dragoons.Value)
		Cash.Parent = Leaderstats
			if Cash then 
				while true do
					wait(2)
					Cash.Value = Cash.Value + 250 
				end
			end	
		local Resource1 = Instance.new("IntValue")
		Resource1.Name = "Wood"
		Resource1.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Wood.Value)
		Resource1.Parent = Leaderstats
		local Resource2 = Instance.new("IntValue")
		Resource2.Name = "Iron"
		Resource2.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Iron.Value)
		Resource2.Parent = Leaderstats
		local Resource3 = Instance.new("IntValue")
		Resource3.Name = "Stone"
		Resource3.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Stone.Value)
		Resource3.Parent = Leaderstats
		local Resource4 = Instance.new("IntValue")
		Resource4.Name = "Metal"
		Resource4.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Metal.Value)
		Resource4.Parent = Leaderstats
		local Resource6 = Instance.new("IntValue")
		Resource6.Name = "Cloth"
		Resource6.Value = data:GetAsync(Player.UserId) or 5
		data:SetAsync(Player.UserId, Player.leaderstats.Cloth.Value)
		Resource6.Parent = Leaderstats
	end				
end)

	
	
game.Players.PlayerRemoving:Connect(function(Player)
	data:SetAsync(Player.UserId, Player.leaderstats.Dragoons.Value) --Change "Points" to the name of your leaderstat.
	data:SetAsync(Player.UserId, Player.leaderstats.Wood.Value)	
	data:SetAsync(Player.UserId, Player.leaderstats.Iron.Value)
	data:SetAsync(Player.UserId, Player.leaderstats.Stone.Value)
	data:SetAsync(Player.UserId, Player.leaderstats.Metal.Value)
	data:SetAsync(Player.UserId, Player.leaderstats.Cloth.Value)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.