ServerScriptService.Main:26: attempt to call a nil value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

i want to do a script that can handle the entire game

  1. What is the issue? Include screenshots / videos if possible!

i get this error and idk how to remove it

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i forgot to add the function so i added it and it stills gets this error, i checked for spelling mistakes and etc.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

honestly, my entire script might not be very efficient but i am making a singleplayer game.

local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService"):GetDataStore("leaderstats")

local OnePlayerTable = {}
OnePlayerTable.__index = OnePlayerTable

function OnePlayerTable.SetPlayer(plr)
	local new = {}
	new._GetData = nil
	new._SetData = nil
	new._Player = plr;
	new._PlayerId = plr.UserId;
	new._Stats = {}
	new._Warnings = 0;
	new._Banned = false;
	new._Pickaxe = "1";
	new._Block = "1";
	new._IsAdmin = false;
	new._BanReason = "Unknown";
	new._Cash = new._Stats.Cash
	new._Rebirths = new._Stats.Rebirths
	new._Prestiges = new._Stats.Prestiges
	new._Metal = new._Stats.Metals
	new._SetStats()
	setmetatable(new, OnePlayerTable)
	return new
end

local Dummy = workspace.NPC.Worker

function OnePlayerTable:_SetStats()
	local plr = self._Player
	
	local l = Instance.new("Folder", plr)
	l.Name = "Stats"

	local c = Instance.new("NumberValue", l)
	c.Name = "Cash"
	c.Value = self._Cash
	local r = Instance.new("NumberValue", l)
	r.Name = "Rebirths"
	r.Value = self._Rebirths
	local p = Instance.new("NumberValue", l)
	p.Name = "Prestiges"
	p.Value = self._Prestiges
	local m = Instance.new("NumberValue", l)
	m.Name = "Metals"
	m.Value = self._Metals
	
	local s,e = pcall(function()
		c.Value = DSS:GetAsync("cash_"..plr.UserId) or 0
		r.Value = DSS:GetAsync("rebirths_"..plr.UserId) or 0
		p.Value = DSS:GetAsync("prestiges_"..plr.UserId) or 0
		m.Value = DSS:GetAsync("metals_"..plr.UserId) or 0
	end)
end

function OnePlayerTable:SaveStats()
	local plr = self._Player
	
	local s,e = pcall(function()
		DSS:SetAsync("cash_"..plr.UserId, self._Cash)
		DSS:SetAsync("rebirths_"..plr.UserId, self._Rebirths)
		DSS:SetAsync("prestiges_"..plr.UserId, self._Prestiges)
		DSS:SetAsync("metals_"..plr.UserId, self._Metals)
	end)
end

function OnePlayerTable:CloneCharacter()
	local plrId = self._PlayerID
	local plr = self._Player
	
	local des = Players:GetHumanoidDescriptionFromUserId(plrId)
	
	if des then
		Dummy.Humanoid:ApplyDescription(des)
		wait(1)
		local PickClone = script.PickaxeSpawnPart:Clone()
		PickClone.Name = "PickaxeSpawnPart"
		PickClone.Parent = Dummy
	end
	
	Dummy.Name = plr.Name
	return
end

function OnePlayerTable:GivePickaxe()
	local PickaxeId = self._Pickaxe
	print(PickaxeId)
end

function OnePlayerTable:WarningsAndBans()
	local plr = self._Players
	local Warnings = self._Warnings
	local Banned = self._Banned
	
	
	if Warnings >= 3 then
		Banned = true
		plr:Kick(self._BanReason)
	end

	if Banned == true then
		plr:Kick(self._BanReason)
	end
end

Players.PlayerAdded:Connect(function(plr)
	
	local playerinfo = OnePlayerTable.SetPlayer(plr)
	
	playerinfo.WarningsAndBans()
	
	playerinfo.CloneCharacter()

	playerinfo.GivePickaxe()
	
	print(playerinfo._Stats)
	
	game.ReplicatedStorage.GetDataTable.OnInvoke = function()
		return OnePlayerTable
	end
	
	game.ReplicatedStorage.GetDataTableClient.OnServerInvoke = function ()
		return OnePlayerTable
	end
end)

Players.PlayerRemoving:Connect(function(plr)
end)



game:BindToClose(function()
	wait(5)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Edit: i comepletly forgot to remove an unwanted variable (it still didnt work)

I updated your script for you

local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService"):GetDataStore("leaderstats")
local DSST = game:GetService("DataStoreService"):GetDataStore("Test")
local HTTP = game:GetService("HttpService")

local OnePlayerTable = {}
OnePlayerTable.__index = OnePlayerTable

function OnePlayerTable:SetPlayer(plr)
	local new = {}
	setmetatable(new, OnePlayerTable)
	new._Player = plr
	new._PlayerId = plr.UserId
	new._Stats = {}
	new._Warnings = 0
	new._Banned = false
	new._Pickaxe = "1"
	new._Block = "1"
	new._IsAdmin = false
	new._BanReason = "Unknown"
	new._Cash = new._Stats.Cash
	new._Rebirths = new._Stats.Rebirths
	new._Prestiges = new._Stats.Prestiges
	new._Metal = new._Stats.Metals
	new:_SetStats()
	return new
end

function OnePlayerTable:_SetStats()
	local plr = self._Player
	local l = Instance.new("Folder", plr)
	l.Name = "Stats"
	local c = Instance.new("NumberValue", l)
	c.Name = "Cash"
	c.Value = self._Cash
	local r = Instance.new("NumberValue", l)
	r.Name = "Rebirths"
	r.Value = self._Rebirths
	local p = Instance.new("NumberValue", l)
	p.Name = "Prestiges"
	p.Value = self._Prestiges
	local m = Instance.new("NumberValue", l)
	m.Name = "Metals"
	m.Value = self._Metals
	local s,e = pcall(function()
		c.Value = DSS:GetAsync("cash_"..plr.UserId) or 0
		r.Value = DSS:GetAsync("rebirths_"..plr.UserId) or 0
		p.Value = DSS:GetAsync("prestiges_"..plr.UserId) or 0
		m.Value = DSS:GetAsync("metals_"..plr.UserId) or 0
	end)
end

function OnePlayerTable:SaveStats()
	local plr = self._Player
	local s,e = pcall(function()
		DSS:SetAsync("cash_"..plr.UserId, self._Cash)
		DSS:SetAsync("rebirths_"..plr.UserId, self._Rebirths)
		DSS:SetAsync("prestiges_"..plr.UserId, self._Prestiges)
		DSS:SetAsync("metals_"..plr.UserId, self._Metals)
	end)
end

function OnePlayerTable:CloneCharacter()
	local plrId = self._PlayerId
	local plr = self._Player
	local des = Players:GetHumanoidDescriptionFromUserId(plrId)
	if des then
		Dummy.Humanoid:ApplyDescription(des)
		wait(1)
		local PickClone = script.PickaxeSpawnPart:Clone()
		PickClone.Name = "PickaxeSpawnPart"
		PickClone.Parent = Dummy
	end
	Dummy.Name = plr.Name
end

function OnePlayerTable:GivePickaxe()
	local PickaxeId = self._Pickaxe
	print(PickaxeId)
end

function OnePlayerTable:WarningsAndBans()
	local plr = self._Player
	local Warnings = self._Warnings
	local Banned = self._Banned
	if Warnings >= 3 then
		Banned = true
		plr:Kick(self._BanReason)
	end
	if Banned then
		plr:Kick(self._BanReason)
	end
end

Players.PlayerAdded:Connect(function(plr)
	local playerinfo = OnePlayerTable:SetPlayer(plr)
	playerinfo:WarningsAndBans()
	playerinfo:CloneCharacter()
	playerinfo:GivePickaxe()
	game.ReplicatedStorage.GetDataTable.OnInvoke = function()
		return OnePlayerTable
	end
	game.ReplicatedStorage.GetDataTableClient.OnServerInvoke = function ()
		return OnePlayerTable
	end
end)

Players.PlayerRemoving:Connect(function(plr)
end)

game:BindToClose(function()
	wait(5)
end)

1 Like

ok thanks alot there is more problems but i can fix those and anyways it will be off topic

On new._SetStats() the . supposed to replace with the : instead of the .

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