ServerScriptService.Files.ScriptsPlace.DataStore2:19: attempt to call a nil value

I have no idea why it does the nil thing, Im trying to load my custom character and so far it gives me this error. Im confused.

The error occurs on the function.

Code:

--// Service //--
local RP = game:GetService("ReplicatedStorage")
local ST = game:GetService("ServerStorage")
local Players = game:GetService("Players")

--// Modules//--
local DataStore2 = require(1936396537)
local DatasFolder = script:FindFirstChild("DSFolder")

local Setup_PlayerData = require(script:FindFirstChild("SetupPlayerData"))

--// Variables //--
local DefaultVsFolder = DatasFolder:FindFirstChild("DefaultValues")
local DefaultValues = {Data_Player = {}}


--// Functions //--

function plrAdded(Player)
	Setup_PlayerData.l(Player,DataStore2,DefaultValues.Data_Player,DefaultVsFolder,"PlayerData")
end


for Index,Player in next,Players:GetPlayers() do
	plrAdded(Player)
end

Players.PlayerAdded:Connect(plrAdded)

Set-Up Function:

local attempt = {}

local DataStoreStage = script.Parent.DSFolder:FindFirstChild(script.Name.."_Stage").Value

attempt.Data = function(Player,DataStore2,DefaultValues,DefaultVsFolder,Key)
	
local function Manager(Player,Type)
	local DataStore = DataStore2(DataStoreStage, Player)


	local function Set_Vals(PlayerData)
		--//Update
		local OldPlayerValues = DataStore:Get(DefaultValues)
		local PlayerValues = {}
		local UpdatedValues = {}

		for Index,PlrVals in next,PlayerData:GetDescendants() do
			if PlrVals:IsA("ValueBase") and PlrVals.Name ~= "OldValue"  then
				local valSet = OldPlayerValues[PlrVals.Name]

				if valSet ~= PlrVals.Value then
					UpdatedValues[PlrVals.Name] = PlrVals.Value
				end
				PlayerValues[PlrVals.Name] = PlrVals.Value
			end
		end

		DataStore:Set(PlayerValues)
		--print("UpdatedPlayerValues:",UpdatedValues)
	end

	local function Get_Vals(PlayerData)
		--// Load Vals
		local DataStore = DataStore2(DataStoreStage, Player)
		local PlayerValues = DataStore:Get(DefaultValues)

		for Index,PlrVals in next,PlayerData:GetDescendants() do
			if PlrVals:IsA("ValueBase") then
				local valSet = PlayerValues[PlrVals.Name]
				if valSet then
					PlrVals.Value = valSet
				end
			end
		end
	end


	local PlayerData = Player:FindFirstChild(Key)
	if PlayerData then
		if Type == "Update" then
			Set_Vals(PlayerData)
		elseif Type == "Load" then	
			Get_Vals(PlayerData)
		end	
	end
end


local function ChangedVals(Player,Folder)
		for index,Vals in ipairs(Folder:GetDescendants()) do
		if Vals:IsA("ValueBase") and Vals.Name ~= "OldValue" then	
			Vals.Changed:Connect(function()
				Manager(Player,"Update")
			end)	
		end
	end
end

local function LocationsValues(Player)
	--//Alocando valores na tabela
	local Folder = DefaultVsFolder:FindFirstChild(Key)
	if not Player:FindFirstChild(Folder.Name) then
		local F = Folder:Clone()
		F.Parent = Player
	end	
	--warn(Folder,"Setado")

	for Index,Val in next,Folder:GetDescendants() do
		if Val:IsA("ValueBase")  and  Val.Name ~= "OldValue" then
			DefaultValues[Val.Name] = Val.Value
		end
	end
end

	
LocationsValues(Player)
Manager(Player,"Load")
Manager(Player,"Update")

local DataPlr = Player:WaitForChild(Key,1)
ChangedVals(Player,DataPlr)	
	

end



return attempt
1 Like

Is it potentially this?

I think so, im currently also puzzled on how to load the datastore using this one. I just somewhat copy and pasted the scripts from the original game but of course I realised it probably doesn’t load it.

EDIT: The data does transfer! It just seems it hasn’t visually put the hats on.

I got another error and its this:

local function LocationsValues(Player)
	
	local Folder = DefaultVsFolder:FindFirstChild(Key) --error
	if not Player:FindFirstChild(Folder.Name) then
		local F = Folder:Clone()
		F.Parent = Player
	end	
	

	for Index,Val in next,Folder:GetDescendants() do
		if Val:IsA("ValueBase")  and  Val.Name ~= "OldValue" then
			DefaultValues[Val.Name] = Val.Value
		end
	end
end

yes sorry now i see, try

local Folder = DefaultyVsFolder:FindFirstChild(“Key”)

or

local Folder = DefaultyVsFolder:WaitForChild(“Key”)

if still dont function try this

local function LocationsValues(Player)
	local Folder= DefaultVsFolder:FindFirstChild("Key")
	if Folder then
		if not Player:FindFirstChild(Folder.Name) then
			local F = Folder:Clone()
			F.Parent = Player
		end	
	end


	for Index,Val in next,Folder:GetDescendants() do
		if Val:IsA("ValueBase")  and  Val.Name ~= "OldValue" then
			DefaultValues[Val.Name] = Val.Value
		end
	end
end

I marked it in the comments. It’s mostly difficult for the game to get the key apparantly.

The

if Folder then

is for detect if Folder it was find if still not work its because Key is not worth it

I tried your function and it managed to get passed the index nil but now says:

ServerScriptService.Files.ScriptsPlace.DataStore2.SetupPlayerData:78: attempt to index nil with 'GetDescendants'

It is where it starts the Index,Val

EDIT: I put it in the loop and it works, there are a few that I can solve so I’ll let you know once its something odd I see.

Ok tell me when :grinning:
or when you want :smiley:

And it went back to the FindFirstChild nil problem again. It sort of looped back onto itself and thinks the Key can’t be found.

did you put a task.wait() in the start of the loop?

No as in it went to this as a error:

		local Folder = DefaultVsFolder:FindFirstChild(Key)

Humm what is the local of DefaultVsFolder

If you look back at the initial post, it should be there.

local DataStore2 = require(1936396537)
local DatasFolder = script:FindFirstChild("DSFolder")

local Setup_PlayerData = require(script:FindFirstChild("SetupPlayerData"))

--// Variables //--
local DefaultVsFolder = DatasFolder:FindFirstChild("DefaultValues")
local DefaultValues = {Data_Player = {}}

so here you dont need to use FindFirstChild right? just use

local DatasFolder = script.DSFolder
---and
local DefaultyVsFolder = DatasFolder:WaitForChild("DefaultyValues")

Possibly. I may try that idea and see what happens.

EDIT: It didnt work as it still indexes it with nil

EDIT2: It works but now im just puzzled with loading it all in

ok so i think the problem is in

local DataFolder = script:FindFirstChild("DSFolder") --- is a module?

is it a module right? so you need to set

local DataFolder = require(script.DSFolder)

and that you need just make

local DefaultVsFolder = DatasFolder.DefaultyValues

It’s fully working now, i’m just a bit confused with loading all the hats since well, it has the data. But i’m just stuck on represeting it all visually.

Here is the script that is responsible for all the visual stuff in the customize game:
However I just need it to load and not prompt the player to redesign the character with the GUIs


--------------------// Services 
local RP   = game:GetService("ReplicatedStorage")

local StarterGui   = game:GetService("StarterGui")
local RunService   = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local TeleportService  = game:GetService("TeleportService")
local UserInputService = game:GetService("UserInputService")

--------------------// Events  / Modules
local CustomRemote  = RP.Customizer.CustomizeStorage.Events:FindFirstChild("OnCustomize")
local RaceSpinFun    = RP.Customizer.CustomizeStorage.Events:FindFirstChild("FunPlayerRace")

local ModuleSpinRace = require(RP.Customizer:FindFirstChild("RaceSpin"))

--------------------// Variables 
local Player = game.Players.LocalPlayer ;repeat wait() until Player.Character
local PlayerData = Player:WaitForChild('PlayerData')
local CustomData = PlayerData:WaitForChild('Customize')
local InfoData   = PlayerData:WaitForChild('Info')

local Mouse  = Player:GetMouse()

local Folder  = RP:WaitForChild("CustomizeStorage")
local Storage = Folder:FindFirstChild("Custom")

local Character  = Player.Character
local Camera     = workspace.CurrentCamera

local Sounds     = RP.CustomizeStorage.Sounds
local MusicLobby = Sounds:FindFirstChild("MusicLobby")

local MainFrame  = script.Parent.Parent
local Handles    = script.Parent.Parent.Handles
local Buttons     = script.Parent.Parent.Buttons
local Effect     = script.Parent.Parent.Effect

local SetReroll  = Handles.All.Race
local SkinColorFrame = Handles.All.SkinColor

local SetColor1   = Handles.All.CoresSelect.SetColor1
local SetColor2   = Handles.All.CoresSelect.SetColor2

local Selection  = Handles.All.Selection

--------------------// Settings
local PlaceIdTP    = 12162886085 ---Teleport place ID / 0 = None

local Coldown      = false
local Coldown2     = false
local onMusic      = false

local Move_Right   = false
local Move_Left    = false
local updateTextRace = true

local TwenMusic    = {[true] = UDim2.new(0, 31,0, 0),[false] = UDim2.new(0, -1,0, 0)}

local coreCall do
	local MAX_RETRIES = 8

	local StarterGui = game:GetService('StarterGui')
	local RunService = game:GetService('RunService')

	function coreCall(method, ...)
		local result = {}
		for retries = 1, MAX_RETRIES do
			result = {pcall(StarterGui[method], StarterGui, ...)}
			if result[1] then
				break
			end
			RunService.Stepped:Wait()
		end
		return unpack(result)
	end
end

coreCall('SetCore', 'ResetButtonCallback', false)

MusicLobby.Playing = true

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame

--//---------------------------------------------
--------------------// Function //---------------------------------------------
--//---------------------------------------------

--------------------- Manager Customize Gui
function OnRemoted(Category,Style,Type,Button)
	if Coldown == true then return end
	Coldown = true
	Sounds.Click:Play()

	if Category == "Color" then
		CustomRemote:FireServer("Color",Style,Type)
	else
		CustomRemote:FireServer("Visual",Style,Type)
	end	
	
	-------------------- Effect
	Button.BackgroundTransparency = 0
	TweenService:Create(Button,TweenInfo.new(.5),{BackgroundTransparency = 1}):Play()
	
	wait(.1)
	Coldown = false
end


--------------------- Rerrol Race
SetReroll.Nick.Text = InfoData.Race.Value

SetReroll.RerolDecal.Button.MouseButton1Down:Connect(function()
	if Coldown == true then return end
	----------
	local ChoseRace = RaceSpinFun:InvokeServer()
	
	if ChoseRace then
		updateTextRace = false
		Coldown = true
		TweenService:Create(SetReroll.Nick,TweenInfo.new(.2),{TextColor3 = Color3.fromRGB(218, 218, 218)}):Play()
		SetReroll.RerolDecal:TweenSize(UDim2.new(0.331, 0,0, 0),"Out","Quad",.1)
		
		----------
		ModuleSpinRace:Rerroll((.1),SetReroll.Nick) -- Client Rerrol (FAKE)
		----------

		wait(.5)
		SetReroll.RerolDecal:TweenSize(UDim2.new(0.331, 0,0.961, 0),"Out","Quad",.25)		
		TweenService:Create(SetReroll.Nick,TweenInfo.new(1),{TextColor3 = Color3.fromRGB(255,255,255)}):Play()
		
		updateTextRace = true
		--print(Player,"New Race",ChoseRace)
		Coldown = false	
	else return	
	end
end)



--------------------- Play Teleport Place
Buttons.Play.Button.MouseButton1Down:Connect(function()
	if PlaceIdTP == 0 then  -- Put place idle in here
		print("Error ID Place!")
		return 
	end
	Coldown = true;Coldown2 = true
	TweenService:Create(Effect,TweenInfo.new(1),{BackgroundTransparency = 0}):Play()
	TeleportService:Teleport(PlaceIdTP)
end)


--------------------- Manager Button Music
Buttons.Music.Button.MouseButton1Down:Connect(function()
	if Coldown2 == true then return end
	Coldown2 = true

	if onMusic == false then
		onMusic = true
		TweenService:Create(MusicLobby,TweenInfo.new(1),{Volume = 0.5}):Play()
		TweenService:Create(Buttons.Music.Decal,TweenInfo.new(.5),{ImageColor3 = Color3.fromRGB(31, 226, 76)}):Play()
	else	
		onMusic = false
		TweenService:Create(MusicLobby,TweenInfo.new(.5),{Volume = 0}):Play()
		TweenService:Create(Buttons.Music.Decal,TweenInfo.new(.5),{ImageColor3 = Color3.fromRGB(226, 31, 34)}):Play()
	end
	
	Buttons.Music.Decal:TweenPosition(TwenMusic[onMusic],"Out","Quad",.1)
	wait(.2)
	Coldown2 = false
end)

--------------------- Manager Interect
for _,vHand  in next,Handles.All:GetChildren() do
for _,vColor in next,Handles.All.SkinColor:GetChildren() do
spawn(function()
	local valueData = CustomData:FindFirstChild(vHand.Name)	
			
	------------------------------------ Refresh
	if valueData then		
		SetColor1.Visible = false	
		SetColor2.Visible = false		

		vHand.Num.Text = valueData.Value	
			
		valueData.Changed:Connect(function(new)
			vHand.Num.Text = new	
		end)	
				
		Selection.Changed:Connect(function(new)		
			if vHand:FindFirstChild("Num") then							
				if new == "Eyes" or new == "Mouths" then		
					SetColor1.Visible = false	
					SetColor2.Visible = false
				else			
					SetColor1.Visible = true	
					SetColor2.Visible = true		
				end			
							
				if vHand.Name == new  then	
			        vHand.nick.TextColor3 = Color3.fromRGB(255,255,255)
					vHand.ImageColor3 = Color3.fromRGB(54, 54, 54)			
				else		
					vHand.nick.TextColor3 = Color3.fromRGB(80, 80, 80)
					vHand.ImageColor3 = Color3.fromRGB(255,255,255)			
				end	
			end			
		end)			
	end			
			
	------------------------------------ Visual Interect
    if vHand:FindFirstChild("Right") then
		local LeftB = vHand.Left
		local RightB = vHand.Right

		vHand.Efect.MouseButton1Down:Connect(function()
			Selection.Value = vHand.Name		
		end)	

		vHand.Efect.MouseEnter:Connect(function()
					vHand.Efect.BackgroundTransparency = 0.3
					
			TweenService:Create(vHand.Efect,TweenInfo.new(.5),{BackgroundTransparency = 1}):Play()	
		end)	
				
		LeftB.MouseButton1Down:Connect(function()	
			OnRemoted("Visual",LeftB.Parent.Name,LeftB.Name,LeftB)	
		end)
		RightB.MouseButton1Down:Connect(function()	
			OnRemoted("Visual",RightB.Parent.Name,RightB.Name,RightB)	
		end)						
	end			
			
			
	------------------------------------ Colors Interect
	if vColor:FindFirstChild("Button") then  	
		vColor.Button.MouseButton1Down:Connect(function()
			OnRemoted("Color","Skin",vColor.Name,vColor.Button)		
		end)	
	end				
			
			
end) end end


--------------------- Update

local function updateColorsRace()
	pcall(function()
		local fold = Storage.Skin:FindFirstChild(InfoData.Race.Value)
		
		for _,skin in ipairs(SkinColorFrame:GetChildren()) do
			local selec = fold:FindFirstChild(skin.Name)

			if selec then
				skin.ImageColor3 = selec.HeadColor3
			end
		end
	end)
end
updateColorsRace()

print("Client Loaded")

InfoData.Race.Changed:Connect(function()
	wait(.1)
	updateColorsRace()
end)


RunService.RenderStepped:Connect(function()
	wait(.1)
	SetReroll.Num.Text = "Spin:"..InfoData.Spin.Value	
	if updateTextRace == true then
	SetReroll.Nick.Text = InfoData.Race.Value	
	end
end)

you are using the data store 2 to load the module you need to set the module inside of the script and make

local DataStore2 = require(script.TheNameOfTheModule)