Attempt to index nil with 'Stat'

local replicatedStorage= game:GetService("ReplicatedStorage")

local ServerStorage= game:GetService("ServerStorage")

local tools = ServerStorage:FindFirstChild("Tools")

local scripts = ServerStorage:FindFirstChild("Script")

local toolConfig = require(game.ServerStorage:WaitForChild("MontalayaciAhmetUSta"):WaitForChild("ToolConfig"))

local remotes = replicatedStorage:FindFirstChild("Remotes")
 remotes.ToolActivatedRemote.OnServerEvent:Connect(function(player)
	warn("Client", player, "activated a tool")
print("Find tool's stats in SV module of:", toolConfig[player.Inventory.EquippedTool.Value]["Stat"]) --Error is here
	if toolConfig[player.Inventory.EquippedTool.Value] then -- if toolConfig["Red"] Blue, etc is found in SV module
		player.leaderstats.Strength.Value += toolConfig[player.Inventory.EquippedTool.Value]["Stat"]
		remotes.TextChange:FireClient(player, toolConfig[player.Inventory.EquippedTool.Value["Stat"]) -- Sending updated data back to client	
	print("MENONLOKOMATÄ°F")	
	end
end)

but it doesn’t print “Menonlokomatif” and I get this error: attempt to index nil with ‘Stat’
screenShoot of ToolConfig


how Can I fix it without changing ToolConfig?

and if I delete the [Stat] at error line It prints " Find tool’s stats in SV module of: nil"

Seems like the equippedTool.Value does not match one of the module’s indecies. try printing this value

print(player.Inventory.EquippedTool.Value)

It will need to be 1, 2, 3, 4, or 5 for your script to work

1 Like

Well I changed script to this and it works now

remotes.ToolActivatedRemote.OnServerEvent:Connect(function(player)
	warn("Client", player, "activated a tool")
	print("Find tool's stats in SV module of:", player.Inventory.EquippedTool.Value)
	local UserTool = player.Inventory.EquippedTool.Value
	for _,i in ipairs(toolConfig) do
		if i.ID == UserTool then -- if toolConfig["Red"] Blue, etc is found in SV module
			player.leaderstats.Strength.Value += i.Stat
			remotes.TextChange:FireClient(player, i.Stat) -- Sending updated data back to client	
			print("MENONLOKOMATÄ°F")	
		end
	end
end)

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